diff options
Diffstat (limited to 'src/lib/Bcfg2/Options')
-rw-r--r-- | src/lib/Bcfg2/Options/Parser.py | 3 | ||||
-rw-r--r-- | src/lib/Bcfg2/Options/Subcommands.py | 38 |
2 files changed, 31 insertions, 10 deletions
diff --git a/src/lib/Bcfg2/Options/Parser.py b/src/lib/Bcfg2/Options/Parser.py index d146e3aa2..b72a495f1 100644 --- a/src/lib/Bcfg2/Options/Parser.py +++ b/src/lib/Bcfg2/Options/Parser.py @@ -141,6 +141,9 @@ class Parser(argparse.ArgumentParser): self.option_list.extend(option.list_options()) option.add_to_parser(self) + for opt in option.list_options(): + opt.default_from_config(self._cfp) + self._defaults_set.append(opt) def add_component(self, component): """ Add a component (and all of its options) to the diff --git a/src/lib/Bcfg2/Options/Subcommands.py b/src/lib/Bcfg2/Options/Subcommands.py index 8972bde00..2ba81e18d 100644 --- a/src/lib/Bcfg2/Options/Subcommands.py +++ b/src/lib/Bcfg2/Options/Subcommands.py @@ -48,6 +48,14 @@ 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 + + #: Additional aliases for the command. The contents of the list gets + #: added to the default command name (the lowercased class name) + aliases = [] + _ws_re = re.compile(r'\s+', flags=re.MULTILINE) def __init__(self): @@ -82,6 +90,7 @@ class Subcommand(object): """ if args is not None: self.parser.namespace = copy.copy(master_setup) + self.parser.parsed = False alist = shlex.split(args) try: setup = self.parser.parse(alist) @@ -141,7 +150,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() @@ -207,15 +218,22 @@ class CommandRegistry(object): else: cmd_obj = cls_or_obj 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 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) + names = [cmdcls.__name__.lower()] + if cmdcls.aliases: + names.extend(cmdcls.aliases) + + for name in names: + self.commands[name] = cmd_obj + + 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) return cmd_obj def register_commands(self, candidates, parent=Subcommand): |