]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
runner: tweaked runner to make it easier to extend with additional subcommands
authorrobk-tahoe <robk-tahoe@allmydata.com>
Wed, 20 Feb 2008 00:05:14 +0000 (17:05 -0700)
committerrobk-tahoe <robk-tahoe@allmydata.com>
Wed, 20 Feb 2008 00:05:14 +0000 (17:05 -0700)
runner provides the main point of entry for the 'tahoe' command, and
provides various subcommands by default. this provides a hook whereby
additional subcommands can be added in in other contexts, providing a
simple way to extend the (sub)commands space available through 'tahoe'

src/allmydata/scripts/runner.py

index fe51dc3817525c3c24e06ce93e193c662b5a122c..a77810b003cea3d84e55cdcad9593008dc4b172a 100644 (file)
@@ -19,19 +19,19 @@ class Options(BaseOptions, usage.Options):
         if not hasattr(self, 'subOptions'):
             raise usage.UsageError("must specify a command")
 
-class OptionsNoNodeControl(Options):
-    synopsis = "Usage:  tahoe <command> [command options]"
+def runner(argv, run_by_human=True, stdout=sys.stdout, stderr=sys.stderr,
+                 install_node_control=True, additional_commands=None):
 
-    subCommands = []
-    subCommands += _general_commands
+    config = Options()
+    if install_node_control:
+        config.subCommands.extend(startstop_node.subCommands)
 
+    ac_dispatch = {}
+    if additional_commands:
+        for ac in additional_commands:
+            config.subCommands.extend(ac.subCommands)
+            ac_dispatch.update(ac.dispatch)
 
-def runner(argv, run_by_human=True, stdout=sys.stdout, stderr=sys.stderr,
-                 install_node_control=True):
-    if install_node_control:
-        config = Options()
-    else:
-        config = OptionsNoNodeControl()
     try:
         config.parseOptions(argv)
     except usage.error, e:
@@ -60,6 +60,8 @@ def runner(argv, run_by_human=True, stdout=sys.stdout, stderr=sys.stderr,
         rc = debug.dispatch[command](so, stdout, stderr)
     elif command in cli.dispatch:
         rc = cli.dispatch[command](so, stdout, stderr)
+    elif command in ac_dispatch:
+        rc = ac_dispatch[command](so, stdout, stderr)
     else:
         raise usage.UsageError()