diff piecrust/main.py @ 57:c8c522dacfea

Add `help` function, cleanup argument handling.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 26 Aug 2014 23:18:32 -0700
parents a62452ab5080
children 64f37c4cce68
line wrap: on
line diff
--- a/piecrust/main.py	Tue Aug 26 23:17:20 2014 -0700
+++ b/piecrust/main.py	Tue Aug 26 23:18:32 2014 -0700
@@ -6,6 +6,7 @@
 import colorama
 from piecrust.app import PieCrust, PieCrustConfiguration, APP_VERSION
 from piecrust.chefutil import format_timed, log_friendly_exception
+from piecrust.commands.base import CommandContext
 from piecrust.environment import StandardEnvironment
 from piecrust.pathutil import SiteNotFoundError, find_app_root
 from piecrust.plugins.base import PluginLoader
@@ -151,6 +152,7 @@
 
     # Setup the arg parser.
     parser = argparse.ArgumentParser(
+            prog='chef',
             description="The PieCrust chef manages your website.")
     parser.add_argument('--version', action='version', version=('%(prog)s ' + APP_VERSION))
     parser.add_argument('--root', help="The root directory of the website.")
@@ -166,13 +168,19 @@
     for c in commands:
         p = subparsers.add_parser(c.name, help=c.description)
         c.setupParser(p, app)
-        p.set_defaults(func=c._runFromChef)
+        p.set_defaults(func=c.checkedRun)
+    help_cmd = next(filter(lambda c: c.name == 'help', commands), None)
+    if help_cmd and help_cmd.has_topics:
+        parser.epilog = ("Additional help topics: " +
+                ', '.join(help_cmd.getTopicNames()))
+
 
     # Parse the command line.
     result = parser.parse_args()
     logger.debug(format_timed(start_time, 'initialized PieCrust', colored=False))
 
     # Run the command!
-    exit_code = result.func(app, result)
+    ctx = CommandContext(app, parser, result)
+    exit_code = result.func(ctx)
     return exit_code