-# Copyright 2012-2013 GRNET S.A. All rights reserved.
+# Copyright 2012-2014 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
from kamaki.cli import exec_cmd, print_error_message, print_subcommands_help
from kamaki.cli.argument import ArgumentParseManager
-from kamaki.cli.utils import print_dict, split_input
+from kamaki.cli.utils import print_dict, split_input, pref_enc
from kamaki.cli.history import History
from kamaki.cli.errors import CLIError
from kamaki.clients import ClientError
undoc_header = 'interactive shell commands:'
+ def emptyline(self):
+ self.lastcmd = ''
+
def postcmd(self, post, line):
if self._context_stack:
self._roll_command()
self.__dict__ = oldcontext
@staticmethod
- def _create_help_method(cmd_name, args, descr, syntax):
+ def _create_help_method(cmd_name, args, required, descr, syntax):
tmp_args = dict(args)
- tmp_args.pop('options', None)
+ #tmp_args.pop('options', None)
tmp_args.pop('cloud', 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
- help_parser.syntax = syntax
- return help_parser.parser.print_help
+ help_parser = ArgumentParseManager(
+ cmd_name, tmp_args, required,
+ syntax=syntax, description=descr, check_required=False)
+ return help_parser.print_help
def _register_command(self, cmd_path):
cmd = self.cmd_tree.get_command(cmd_path)
<cmd> <term> <term> <args> is always parsed to most specific
even if cmd_term_term is not a terminal path
"""
+ line = line.decode(pref_enc)
subcmd, cmd_args = cmd.parse_out(split_input(line))
self._history.add(' '.join([cmd.path.replace('_', ' '), line]))
cmd_parser = ArgumentParseManager(
if subcmd.is_command: # exec command
try:
cls = subcmd.cmd_class
+ cmd_parser.required = getattr(cls, 'required', None)
ldescr = getattr(cls, 'long_description', '')
if subcmd.path == 'history_run':
instance = cls(
self.auth_base, self.cloud)
cmd_parser.update_arguments(instance.arguments)
cmd_parser.arguments = instance.arguments
+ subpath = subcmd.path.split('_')[
+ (len(cmd.path.split('_')) - 1):]
cmd_parser.syntax = '%s %s' % (
- subcmd.path.replace('_', ' '), cls.syntax)
+ ' '.join(subpath), instance.syntax)
help_method = self._create_help_method(
cmd.name, cmd_parser.arguments,
- subcmd.help, cmd_parser.syntax)
+ cmd_parser.required, subcmd.help, cmd_parser.syntax)
if '-h' in cmd_args or '--help' in cmd_args:
help_method()
if ldescr.strip():
self.auth_base = auth_base
self.cloud = cloud
self._parser = parser
- self._history = History(
- parser.arguments['config'].get_global('history_file'))
+ cnf = parser.arguments['config']
+ self._history = History(cnf.get('global', 'history_file'))
+ self._history.limit = cnf.get('global', 'history_limit')
if path:
cmd = self.cmd_tree.get_command(path)
intro = cmd.path.replace('_', ' ')
else:
intro = self.cmd_tree.name
- acceptable = parser.arguments['config'].get_groups()
+ acceptable = parser.arguments['config'].groups
total = self.cmd_tree.groups.keys()
self.cmd_tree.exclude(set(total).difference(acceptable))