diff options
author | Alexander Sulfrian <alexander.sulfrian@fu-berlin.de> | 2015-09-08 18:44:16 +0200 |
---|---|---|
committer | Sol Jerome <sol.jerome@gmail.com> | 2015-10-13 13:11:01 -0500 |
commit | f796972188a158bb5fe8fc5439ebacddbed41867 (patch) | |
tree | f85f9dc170f5f18061e57514e0f21dedb1c49c4b /src/lib/Bcfg2/Options | |
parent | 3e1e0536aa9924af592e02dbc70bcfccbcbbb379 (diff) | |
download | bcfg2-f796972188a158bb5fe8fc5439ebacddbed41867.tar.gz bcfg2-f796972188a158bb5fe8fc5439ebacddbed41867.tar.bz2 bcfg2-f796972188a158bb5fe8fc5439ebacddbed41867.zip |
Options: Add possibility to have interactive only Subcommands
Some subcommands only makes sense, if they are called from an interactive
shell and to interface a running server. Now we can mark a Subcommand
as only_interactive and it will not be callable as argument from the command
line.
Diffstat (limited to 'src/lib/Bcfg2/Options')
-rw-r--r-- | src/lib/Bcfg2/Options/Subcommands.py | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/lib/Bcfg2/Options/Subcommands.py b/src/lib/Bcfg2/Options/Subcommands.py index a9de738a4..a23537fc4 100644 --- a/src/lib/Bcfg2/Options/Subcommands.py +++ b/src/lib/Bcfg2/Options/Subcommands.py @@ -48,6 +48,10 @@ class Subcommand(object): #: one, ``bcfg2-admin`` does not.) interactive = True + #: Whether or not to expose this command as command line parameter + #: or only in an interactive :class:`cmd.Cmd` shell. + only_interactive = False + _ws_re = re.compile(r'\s+', flags=re.MULTILINE) def __init__(self): @@ -142,7 +146,9 @@ class Help(Subcommand): self._registry = registry def run(self, setup): - commands = self._registry.commands + commands = dict((name, cmd) + for (name, cmd) in self._registry.commands.items() + if not cmd.only_interactive) if setup.command: try: commands[setup.command].parser.print_help() @@ -210,10 +216,13 @@ class CommandRegistry(object): cmdcls = cmd_obj.__class__ name = cmdcls.__name__.lower() self.commands[name] = cmd_obj - # py2.5 can't mix *magic and non-magical keyword args, thus - # the **dict(...) - self.subcommand_options.append( - Subparser(*cmdcls.options, **dict(name=name, help=cmdcls.__doc__))) + + if not cmdcls.only_interactive: + # py2.5 can't mix *magic and non-magical keyword args, thus + # the **dict(...) + self.subcommand_options.append( + Subparser(*cmdcls.options, **dict(name=name, + help=cmdcls.__doc__))) if issubclass(self.__class__, cmd.Cmd) and cmdcls.interactive: setattr(self, "do_%s" % name, cmd_obj) setattr(self, "help_%s" % name, cmd_obj.parser.print_help) |