Commit 320aac17 authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Exclude unset optional cmd groups

Refs: #4114

E.g. the cyclades spec package contains the non-optional group "server" and
the optional group "floatingip". Now kamaki can load only the "server"
group, except if the user requests the loading of "floatingip" group too.
parent 023d7ab0
......@@ -340,13 +340,15 @@ def _groups_help(arguments):
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(
......
......@@ -442,8 +442,7 @@ class ArgumentParseManager(object):
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
......@@ -513,14 +512,11 @@ class ArgumentParseManager(object):
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)
......
......@@ -310,6 +310,10 @@ class Shell(Cmd):
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)
......
......@@ -137,6 +137,10 @@ class CommandTree(object):
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:
......
......@@ -88,6 +88,7 @@ DEFAULTS = {
# Optional command specs:
# 'livetest_cli': 'livetest',
# 'astakos_cli': 'snf-astakos'
# 'floating_cli': 'cyclades'
},
CLOUD_PREFIX:
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment