from kamaki.cli.history import History
from kamaki.cli.errors import CLIError
from kamaki.clients import ClientError
+from kamaki.cli.logger import add_file_logger
+
+log = add_file_logger(__name__)
def _init_shell(exe_string, parser):
def _restore(self, oldcontext):
self.__dict__ = oldcontext
+ @staticmethod
+ def _create_help_method(cmd_name, args, descr):
+ tmp_args = dict(args)
+ tmp_args.pop('options', None)
+ tmp_args.pop('debug', None)
+ tmp_args.pop('verbose', None)
+ tmp_args.pop('include', None)
+ tmp_args.pop('silent', None)
+ tmp_args.pop('config', None)
+ help_parser = ArgumentParseManager(cmd_name, tmp_args)
+ help_parser.parser.description = descr
+ return help_parser.parser.print_help
+
def _register_command(self, cmd_path):
cmd = self.cmd_tree.get_command(cmd_path)
arguments = self._parser.arguments
"""
subcmd, cmd_args = cmd.parse_out(split_input(line))
self._history.add(' '.join([cmd.path.replace('_', ' '), line]))
- tmp_args = dict(self._parser.arguments)
- tmp_args.pop('options', None)
- tmp_args.pop('debug', None)
- tmp_args.pop('verbose', None)
- tmp_args.pop('include', None)
- tmp_args.pop('silent', None)
- cmd_parser = ArgumentParseManager(cmd.name, dict(tmp_args))
-
+ cmd_parser = ArgumentParseManager(
+ cmd.name, dict(self._parser.arguments))
cmd_parser.parser.description = subcmd.help
# exec command or change context
cmd_parser.arguments = instance.arguments
cmd_parser.syntax = '%s %s' % (
subcmd.path.replace('_', ' '), cls.syntax)
+ help_method = self._create_help_method(
+ cmd.name, cmd_parser.arguments, subcmd.help)
if '-h' in cmd_args or '--help' in cmd_args:
- cmd_parser.parser.print_help()
+ help_method()
if ldescr.strip():
print('\nDetails:')
print('%s' % ldescr)
name,
arg.default)
- exec_cmd(
- instance,
- cmd_parser.unparsed,
- cmd_parser.parser.print_help)
+ exec_cmd(instance, cmd_parser.unparsed, help_method)
#[term for term in cmd_parser.unparsed\
# if not term.startswith('-')],
except (ClientError, CLIError) as err: