diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Bcfg2/Options/Subcommands.py | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/src/lib/Bcfg2/Options/Subcommands.py b/src/lib/Bcfg2/Options/Subcommands.py index a23537fc4..2ba81e18d 100644 --- a/src/lib/Bcfg2/Options/Subcommands.py +++ b/src/lib/Bcfg2/Options/Subcommands.py @@ -52,6 +52,10 @@ class Subcommand(object): #: 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): @@ -214,18 +218,22 @@ class CommandRegistry(object): else: cmd_obj = cls_or_obj cmdcls = cmd_obj.__class__ - name = cmdcls.__name__.lower() - 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) + 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): |