Signed-off-by: Karl Hasselström <kha@xxxxxxxxxxx> --- stgit/main.py | 25 +++++++++++++------------ stgit/utils.py | 5 +++++ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/stgit/main.py b/stgit/main.py index a03447f..95e25f8 100644 --- a/stgit/main.py +++ b/stgit/main.py @@ -23,6 +23,7 @@ from optparse import OptionParser import stgit.commands from stgit.out import * +from stgit import utils # # The commands map @@ -39,11 +40,11 @@ class Commands(dict): if not candidates: out.error('Unknown command: %s' % key, 'Try "%s help" for a list of supported commands' % prog) - sys.exit(1) + sys.exit(utils.STGIT_GENERAL_ERROR) elif len(candidates) > 1: out.error('Ambiguous command: %s' % key, 'Candidates are: %s' % ', '.join(candidates)) - sys.exit(1) + sys.exit(utils.STGIT_GENERAL_ERROR) return candidates[0] @@ -206,7 +207,7 @@ def main(): print >> sys.stderr, 'usage: %s <command>' % prog print >> sys.stderr, \ ' Try "%s --help" for a list of supported commands' % prog - sys.exit(1) + sys.exit(utils.STGIT_GENERAL_ERROR) cmd = sys.argv[1] @@ -216,13 +217,13 @@ def main(): sys.argv[2] = '--help' else: print_help() - sys.exit(0) + 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)) - sys.exit(1) + sys.exit(utils.STGIT_GENERAL_ERROR) sys.argv[0] += ' %s' % cmd command = commands[cmd] @@ -232,16 +233,16 @@ def main(): pager(parser.format_help()) else: print_help() - sys.exit(0) + 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 - sys.exit(0) + sys.exit(utils.STGIT_SUCCESS) if cmd in ['copyright']: print __copyright__ - sys.exit(0) + sys.exit(utils.STGIT_SUCCESS) # re-build the command line arguments cmd = commands.canonical_cmd(cmd) @@ -265,7 +266,7 @@ def main(): debug_level = int(os.environ.get('STGIT_DEBUG_LEVEL', 0)) except ValueError: out.error('Invalid STGIT_DEBUG_LEVEL environment variable') - sys.exit(1) + sys.exit(utils.STGIT_GENERAL_ERROR) try: directory.setup() @@ -284,8 +285,8 @@ def main(): if debug_level > 0: raise else: - sys.exit(2) + sys.exit(utils.STGIT_COMMAND_ERROR) except KeyboardInterrupt: - sys.exit(1) + sys.exit(utils.STGIT_GENERAL_ERROR) - sys.exit(0) + sys.exit(utils.STGIT_SUCCESS) diff --git a/stgit/utils.py b/stgit/utils.py index 837c6c2..29a5f63 100644 --- a/stgit/utils.py +++ b/stgit/utils.py @@ -301,3 +301,8 @@ def make_message_options(): 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 - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html