Signed-off-by: Karl Hasselström <kha@treskal.com>
import stgit.commands
from stgit.out import *
import stgit.commands
from stgit.out import *
if not candidates:
out.error('Unknown command: %s' % key,
'Try "%s help" for a list of supported commands' % prog)
if not candidates:
out.error('Unknown command: %s' % key,
'Try "%s help" for a list of supported commands' % prog)
+ sys.exit(utils.STGIT_GENERAL_ERROR)
elif len(candidates) > 1:
out.error('Ambiguous command: %s' % key,
'Candidates are: %s' % ', '.join(candidates))
elif len(candidates) > 1:
out.error('Ambiguous command: %s' % key,
'Candidates are: %s' % ', '.join(candidates))
+ sys.exit(utils.STGIT_GENERAL_ERROR)
print >> sys.stderr, 'usage: %s <command>' % prog
print >> sys.stderr, \
' Try "%s --help" for a list of supported commands' % prog
print >> sys.stderr, 'usage: %s <command>' % prog
print >> sys.stderr, \
' Try "%s --help" for a list of supported commands' % prog
+ sys.exit(utils.STGIT_GENERAL_ERROR)
sys.argv[2] = '--help'
else:
print_help()
sys.argv[2] = '--help'
else:
print_help()
+ sys.exit(utils.STGIT_SUCCESS)
if cmd == 'help':
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:
out.error('%s help: "%s" command unknown' % (prog, cmd))
if cmd == 'help':
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:
out.error('%s help: "%s" command unknown' % (prog, cmd))
+ sys.exit(utils.STGIT_GENERAL_ERROR)
sys.argv[0] += ' %s' % cmd
command = commands[cmd]
sys.argv[0] += ' %s' % cmd
command = commands[cmd]
pager(parser.format_help())
else:
print_help()
pager(parser.format_help())
else:
print_help()
+ sys.exit(utils.STGIT_SUCCESS)
if cmd in ['-v', '--version', 'version']:
from stgit.version import version
print 'Stacked GIT %s' % version
os.system('git --version')
print 'Python version %s' % sys.version
if cmd in ['-v', '--version', 'version']:
from stgit.version import version
print 'Stacked GIT %s' % version
os.system('git --version')
print 'Python version %s' % sys.version
+ sys.exit(utils.STGIT_SUCCESS)
if cmd in ['copyright']:
print __copyright__
if cmd in ['copyright']:
print __copyright__
+ sys.exit(utils.STGIT_SUCCESS)
# re-build the command line arguments
cmd = commands.canonical_cmd(cmd)
# re-build the command line arguments
cmd = commands.canonical_cmd(cmd)
debug_level = int(os.environ.get('STGIT_DEBUG_LEVEL', 0))
except ValueError:
out.error('Invalid STGIT_DEBUG_LEVEL environment variable')
debug_level = int(os.environ.get('STGIT_DEBUG_LEVEL', 0))
except ValueError:
out.error('Invalid STGIT_DEBUG_LEVEL environment variable')
+ sys.exit(utils.STGIT_GENERAL_ERROR)
if debug_level > 0:
raise
else:
if debug_level > 0:
raise
else:
+ sys.exit(utils.STGIT_COMMAND_ERROR)
except KeyboardInterrupt:
except KeyboardInterrupt:
+ sys.exit(utils.STGIT_GENERAL_ERROR)
+ sys.exit(utils.STGIT_SUCCESS)
m('--save-template', action = 'callback', callback = templ_callback,
metavar = 'FILE', dest = 'save_template', type = 'string',
help = 'save the message template to FILE and exit')]
m('--save-template', action = 'callback', callback = templ_callback,
metavar = 'FILE', dest = 'save_template', type = 'string',
help = 'save the message template to FILE and exit')]
+
+# Exit codes.
+STGIT_SUCCESS = 0 # everything's OK
+STGIT_GENERAL_ERROR = 1 # seems to be non-command-specific error
+STGIT_COMMAND_ERROR = 2 # seems to be a command that failed