runner: tweaked runner to make it easier to extend with additional subcommands
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'
This commit is contained in:
parent
f75c17ed29
commit
21f2d03203
|
@ -19,19 +19,19 @@ class Options(BaseOptions, usage.Options):
|
||||||
if not hasattr(self, 'subOptions'):
|
if not hasattr(self, 'subOptions'):
|
||||||
raise usage.UsageError("must specify a command")
|
raise usage.UsageError("must specify a command")
|
||||||
|
|
||||||
class OptionsNoNodeControl(Options):
|
|
||||||
synopsis = "Usage: tahoe <command> [command options]"
|
|
||||||
|
|
||||||
subCommands = []
|
|
||||||
subCommands += _general_commands
|
|
||||||
|
|
||||||
|
|
||||||
def runner(argv, run_by_human=True, stdout=sys.stdout, stderr=sys.stderr,
|
def runner(argv, run_by_human=True, stdout=sys.stdout, stderr=sys.stderr,
|
||||||
install_node_control=True):
|
install_node_control=True, additional_commands=None):
|
||||||
|
|
||||||
|
config = Options()
|
||||||
if install_node_control:
|
if install_node_control:
|
||||||
config = Options()
|
config.subCommands.extend(startstop_node.subCommands)
|
||||||
else:
|
|
||||||
config = OptionsNoNodeControl()
|
ac_dispatch = {}
|
||||||
|
if additional_commands:
|
||||||
|
for ac in additional_commands:
|
||||||
|
config.subCommands.extend(ac.subCommands)
|
||||||
|
ac_dispatch.update(ac.dispatch)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
config.parseOptions(argv)
|
config.parseOptions(argv)
|
||||||
except usage.error, e:
|
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)
|
rc = debug.dispatch[command](so, stdout, stderr)
|
||||||
elif command in cli.dispatch:
|
elif command in cli.dispatch:
|
||||||
rc = cli.dispatch[command](so, stdout, stderr)
|
rc = cli.dispatch[command](so, stdout, stderr)
|
||||||
|
elif command in ac_dispatch:
|
||||||
|
rc = ac_dispatch[command](so, stdout, stderr)
|
||||||
else:
|
else:
|
||||||
raise usage.UsageError()
|
raise usage.UsageError()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue