Auto-generate man pages for all StGit commands
[stgit] / stgit / main.py
index 663fdec..55c467c 100644 (file)
@@ -19,11 +19,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os, traceback
-from optparse import OptionParser
 
 import stgit.commands
 from stgit.out import *
-from stgit import utils
+from stgit import argparse, run, utils
 
 #
 # The commands map
@@ -59,7 +58,6 @@ class Commands(dict):
         return getattr(stgit.commands, cmd_mod)
 
 commands = Commands({
-    'applied':          'applied',
     'branch':           'branch',
     'delete':           'delete',
     'diff':             'diff',
@@ -96,7 +94,6 @@ commands = Commands({
     'status':           'status',
     'sync':             'sync',
     'top':              'top',
-    'unapplied':        'unapplied',
     'uncommit':         'uncommit',
     'unhide':           'unhide'
     })
@@ -107,7 +104,6 @@ repocommands = (
     'id',
     )
 stackcommands = (
-    'applied',
     'branch',
     'clean',
     'coalesce',
@@ -125,7 +121,6 @@ stackcommands = (
     'series',
     'sink',
     'top',
-    'unapplied',
     'uncommit',
     'unhide',
     )
@@ -192,7 +187,7 @@ def print_help():
 #
 # The main function (command dispatcher)
 #
-def main():
+def _main():
     """The main function
     """
     global prog
@@ -223,8 +218,7 @@ def main():
 
             sys.argv[0] += ' %s' % cmd
             command = commands[cmd]
-            parser = OptionParser(usage = command.usage,
-                                  option_list = command.options)
+            parser = argparse.make_option_parser(command)
             from pydoc import pager
             pager(parser.format_help())
         else:
@@ -246,8 +240,7 @@ def main():
     del(sys.argv[1])
 
     command = commands[cmd]
-    usage = command.usage.split('\n')[0].strip()
-    parser = OptionParser(usage = usage, option_list = command.options)
+    parser = argparse.make_option_parser(command)
     options, args = parser.parse_args()
     directory = command.directory
 
@@ -281,6 +274,10 @@ def main():
         if debug_level > 0:
             traceback.print_exc()
         sys.exit(utils.STGIT_COMMAND_ERROR)
+    except SystemExit:
+        # Triggered by the option parser when it finds bad commandline
+        # parameters.
+        sys.exit(utils.STGIT_COMMAND_ERROR)
     except KeyboardInterrupt:
         sys.exit(utils.STGIT_GENERAL_ERROR)
     except:
@@ -289,3 +286,9 @@ def main():
         sys.exit(utils.STGIT_BUG_ERROR)
 
     sys.exit(ret or utils.STGIT_SUCCESS)
+
+def main():
+    try:
+        _main()
+    finally:
+        run.finish_logging()