from optparse import OptionParser
import stgit.commands
+from stgit.out import *
#
# The commands map
candidates = [cmd for cmd in self.keys() if cmd.startswith(key)]
if not candidates:
- print >> sys.stderr, 'Unknown command: %s' % key
- print >> sys.stderr, ' Try "%s help" for a list of ' \
- 'supported commands' % prog
+ out.error('Unknown command: %s' % key,
+ 'Try "%s help" for a list of supported commands' % prog)
sys.exit(1)
elif len(candidates) > 1:
- print >> sys.stderr, 'Ambiguous command: %s' % key
- print >> sys.stderr, ' Candidates are: %s' \
- % ', '.join(candidates)
+ out.error('Ambiguous command: %s' % key,
+ 'Candidates are: %s' % ', '.join(candidates))
sys.exit(1)
return candidates[0]
'clone': 'clone',
'commit': 'commit',
'cp': 'copy',
+ 'edit': 'edit',
'export': 'export',
'files': 'files',
'float': 'float',
)
patchcommands = (
'delete',
+ 'edit',
'export',
'files',
'fold',
if len(sys.argv) == 3 and not sys.argv[2] in ['-h', '--help']:
cmd = commands.canonical_cmd(sys.argv[2])
if not cmd in commands:
- print >> sys.stderr, '%s help: "%s" command unknown' \
- % (prog, cmd)
+ out.error('%s help: "%s" command unknown' % (prog, cmd))
sys.exit(1)
sys.argv[0] += ' %s' % cmd
sys.exit(0)
# re-build the command line arguments
- sys.argv[0] += ' %s' % commands.canonical_cmd(cmd)
+ cmd = commands.canonical_cmd(cmd)
+ sys.argv[0] += ' %s' % cmd
del(sys.argv[1])
command = commands[cmd]
usage = command.usage.split('\n')[0].strip()
parser = OptionParser(usage = usage, option_list = command.options)
options, args = parser.parse_args()
+ directory = command.directory
# These modules are only used from this point onwards and do not
# need to be imported earlier
+ from stgit.exception import StgException
from stgit.config import config_setup
from ConfigParser import ParsingError, NoSectionError
- from stgit.stack import Series, StackException
- from stgit.git import GitException
- from stgit.commands.common import CmdException
- from stgit.gitmergeonefile import GitMergeException
- from stgit.utils import EditorException
+ from stgit.stack import Series
try:
- debug_level = int(os.environ['STGIT_DEBUG_LEVEL'])
- except KeyError:
- debug_level = 0
+ debug_level = int(os.environ.get('STGIT_DEBUG_LEVEL', 0))
except ValueError:
- print >> sys.stderr, 'Invalid STGIT_DEBUG_LEVEL environment variable'
+ out.error('Invalid STGIT_DEBUG_LEVEL environment variable')
sys.exit(1)
try:
+ directory.setup()
config_setup()
# 'clone' doesn't expect an already initialised GIT tree. A Series
stgit.commands.common.crt_series = command.crt_series
command.func(parser, options, args)
- except (IOError, ParsingError, NoSectionError, CmdException,
- StackException, GitException, GitMergeException,
- EditorException), err:
+ except (StgException, IOError, ParsingError, NoSectionError), err:
print >> sys.stderr, '%s %s: %s' % (prog, cmd, err)
- if debug_level:
+ if debug_level > 0:
raise
else:
sys.exit(2)