Revision 334338ce kamaki/cli/one_command.py
b/kamaki/cli/one_command.py | ||
---|---|---|
31 | 31 |
# interpreted as representing official policies, either expressed |
32 | 32 |
# or implied, of GRNET S.A.command |
33 | 33 |
|
34 |
from kamaki.logger import get_logger |
|
35 |
|
|
36 | 34 |
from kamaki.cli import get_command_group, set_command_params |
37 | 35 |
from kamaki.cli import print_subcommands_help, exec_cmd, update_parser_help |
38 | 36 |
from kamaki.cli import _groups_help, _load_spec_module |
39 |
|
|
40 |
|
|
41 |
kloger = get_logger('kamaki.cli') |
|
37 |
from kamaki.cli import kloger |
|
38 |
from kamaki.cli.errors import CLIUnknownCommand |
|
42 | 39 |
|
43 | 40 |
|
44 | 41 |
def _get_cmd_tree_from_spec(spec, cmd_tree_list): |
45 | 42 |
for tree in cmd_tree_list: |
46 | 43 |
if tree.name == spec: |
47 | 44 |
return tree |
48 |
return None
|
|
45 |
raise CLIUnknownCommand('Unknown command: %s' % spec)
|
|
49 | 46 |
|
50 | 47 |
|
51 | 48 |
def _get_best_match_from_cmd_tree(cmd_tree, unparsed): |
... | ... | |
72 | 69 |
_best_match = [] |
73 | 70 |
|
74 | 71 |
spec_module = _load_spec_module(group, parser.arguments, '_commands') |
75 |
|
|
72 |
if spec_module is None: |
|
73 |
raise CLIUnknownCommand( |
|
74 |
'Could not find specs for %s commands' % group, |
|
75 |
details=[ |
|
76 |
'Make sure %s is a valid command group' % group, |
|
77 |
'Refer to kamaki documentation for setting custom command', |
|
78 |
'groups or overide existing ones']) |
|
76 | 79 |
cmd_tree = _get_cmd_tree_from_spec(group, spec_module._commands) |
77 | 80 |
|
78 | 81 |
if _best_match: |
... | ... | |
81 | 84 |
cmd = _get_best_match_from_cmd_tree(cmd_tree, parser.unparsed) |
82 | 85 |
_best_match = cmd.path.split('_') |
83 | 86 |
if cmd is None: |
84 |
kloger.info( |
|
85 |
'Unexpected error: failed to load command (-d for details)') |
|
87 |
kloger.info('Unexpected error: failed to load command (-d for more)') |
|
86 | 88 |
exit(1) |
87 | 89 |
|
88 | 90 |
update_parser_help(parser, cmd) |
Also available in: Unified diff