global _debug
global kloger
descriptions = {}
+ acceptable_groups = arguments['config'].get_groups()
for cmd_group, spec in arguments['config'].get_cli_specs():
pkg = _load_spec_module(spec, arguments, '_commands')
if pkg:
cmds = getattr(pkg, '_commands')
try:
for cmd in cmds:
- descriptions[cmd.name] = cmd.description
+ if cmd.name in acceptable_groups:
+ descriptions[cmd.name] = cmd.description
except TypeError:
if _debug:
kloger.warning(
the parsers arguments specification
"""
self.parser = ArgumentParser(
- add_help=False,
- formatter_class=RawDescriptionHelpFormatter)
+ add_help=False, formatter_class=RawDescriptionHelpFormatter)
self.syntax = '%s <cmd_group> [<cmd_subbroup> ...] <cmd>' % exe
if arguments:
self.arguments = arguments
self.update_parser()
def parse(self, new_args=None):
- """Do parse user input"""
+ """Parse user input"""
try:
- if new_args:
- self._parsed, unparsed = self.parser.parse_known_args(new_args)
- else:
- self._parsed, unparsed = self.parser.parse_known_args()
+ pkargs = (new_args,) if new_args else ()
+ self._parsed, unparsed = self.parser.parse_known_args(*pkargs)
except SystemExit:
- # deal with the fact that argparse error system is STUPID
raiseCLIError(CLISyntaxError('Argument Syntax Error'))
for name, arg in self.arguments.items():
arg.value = getattr(self._parsed, name, arg.default)
else:
intro = self.cmd_tree.name
+ acceptable = parser.arguments['config'].get_groups()
+ total = self.cmd_tree.get_group_names()
+ self.cmd_tree.exclude(set(total).difference(acceptable))
+
for subcmd in self.cmd_tree.get_subcommands(path):
self._register_command(subcmd.path)
self.name = name
self.description = description
+ def exclude(self, groups_to_exclude=[]):
+ for group in groups_to_exclude:
+ self.groups.pop(group, None)
+
def add_command(self, command_path, description=None, cmd_class=None):
terms = command_path.split('_')
try:
# Optional command specs:
# 'livetest_cli': 'livetest',
# 'astakos_cli': 'snf-astakos'
+ # 'floating_cli': 'cyclades'
},
CLOUD_PREFIX:
{