git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[StGit PATCH 5/5] Name the exit codes to improve legibility

From
Karl Hasselström <kha@treskal.com>
Date
Dec 14, 2007, 06:25 UTC
Message-ID
<20071214062527.29148.7928.stgit@yoghurt>
In-Reply-To
<20071214062251.29148.86191.stgit@yoghurt>
Signed-off-by: Karl Hasselström <kha@treskal.com>
---
 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
Previous: Karl HasselströmNext: Karl Hasselström
Message 7 of 8 in “Various odds and ends”
  1. 0/5 Various odds and endsKarl Hasselström, Dec 14, 2007
  2. 1/5 Added --save-template flag to edit commandKarl Hasselström, Dec 14, 2007
  3. 2/5 Treat filename '-' as stdin/stdout in editKarl Hasselström, Dec 14, 2007
  4. 3/5 Let parse_patch take a string instead of a file parameterKarl Hasselström, Dec 14, 2007
  5. 4/5 Make generic --message/--file/--save-template flagsKarl Hasselström, Dec 14, 2007
  6. Karl HasselströmDec 14, 2007
  7. 5/5 Name the exit codes to improve legibilityKarl Hasselström, Dec 14, 2007
  8. Karl HasselströmDec 14, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.