git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Karl Hasselström" <kha@treskal.com>
To: Catalin Marinas <catalin.marinas@gmail.com>
Cc: git@vger.kernel.org, "David Kågedal" <davidk@lysator.liu.se>
Subject: [StGit PATCH 5/5] Name the exit codes to improve legibility
Date: Fri, 14 Dec 2007 07:25:27 +0100	[thread overview]
Message-ID: <20071214062527.29148.7928.stgit@yoghurt> (raw)
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

  parent reply	other threads:[~2007-12-14  6:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-14  6:24 [StGit PATCH 0/5] Various odds and ends Karl Hasselström
2007-12-14  6:25 ` [StGit PATCH 1/5] Added --save-template flag to edit command Karl Hasselström
2007-12-14  6:25 ` [StGit PATCH 2/5] Treat filename '-' as stdin/stdout in edit Karl Hasselström
2007-12-14  6:25 ` [StGit PATCH 3/5] Let parse_patch take a string instead of a file parameter Karl Hasselström
2007-12-14  6:25 ` [StGit PATCH 4/5] Make generic --message/--file/--save-template flags Karl Hasselström
2007-12-14  6:44   ` Karl Hasselström
2007-12-14  6:25 ` Karl Hasselström [this message]
2007-12-14  6:45   ` [StGit PATCH 5/5] Name the exit codes to improve legibility Karl Hasselström

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20071214062527.29148.7928.stgit@yoghurt \
    --to=kha@treskal.com \
    --cc=catalin.marinas@gmail.com \
    --cc=davidk@lysator.liu.se \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).