Update copyright dates for changes files
[kamaki] / kamaki / cli / command_shell.py
index abf2405..b9391bc 100644 (file)
@@ -1,4 +1,4 @@
-# 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 cmd import Cmd
 from os import popen
-from sys import stdout, stderr
+from sys import stdout
 
 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
@@ -175,10 +175,9 @@ class Shell(Cmd):
         tmp_args.pop('verbose', None)
         tmp_args.pop('silent', None)
         tmp_args.pop('config', None)
-        help_parser = ArgumentParseManager(cmd_name, tmp_args, required)
-        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):
@@ -191,6 +190,7 @@ class Shell(Cmd):
                 <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(
@@ -213,11 +213,13 @@ class Shell(Cmd):
                             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, cmd_parser.required,
-                        subcmd.help, cmd_parser.syntax)
+                        cmd.name, cmd_parser.arguments,
+                        cmd_parser.required, subcmd.help, cmd_parser.syntax)
                     if '-h' in cmd_args or '--help' in cmd_args:
                         help_method()
                         if ldescr.strip():
@@ -306,8 +308,9 @@ class Shell(Cmd):
         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('_', ' ')