History as command
authorStavros Sachtouris <saxtouri@admin.grnet.gr>
Mon, 8 Oct 2012 16:15:54 +0000 (19:15 +0300)
committerStavros Sachtouris <saxtouri@admin.grnet.gr>
Mon, 8 Oct 2012 16:15:54 +0000 (19:15 +0300)
kamaki/cli/__init__.py
kamaki/cli/argument.py
kamaki/cli/commands/pithos_cli.py
kamaki/cli/config.py

index cba21d1..568f70a 100644 (file)
@@ -57,6 +57,7 @@ from .config import Config #TO BE REMOVED
 from .utils import bold, magenta, red, yellow, print_list, print_dict
 from .command_tree import CommandTree
 from argument import _arguments, parse_known_args
+from .history import History
 
 cmd_spec_locations = [
     'kamaki.cli.commands',
@@ -187,6 +188,8 @@ def shallow_load():
 
 def load_group_package(group, reload_package=False):
     spec_pkg = _arguments['config'].value.get(group, 'cli')
+    if spec_pkg is None:
+        return None
     for location in cmd_spec_locations:
         location += spec_pkg if location == '' else ('.'+spec_pkg)
         try:
@@ -246,17 +249,11 @@ def one_command():
     _help = False
     _verbose = False
     try:
-
         exe = basename(argv[0])
         parser = _init_parser(exe)
         parsed, unparsed = parse_known_args(parser)
-        _history = _arguments['history']
-        if _history.value:
-            cmd_list = [term for term in argv if term not in _history.parsed_name]
-            print_list(_history.get(' '.join(cmd_list)))
-            _arguments['history'].add(' '.join(argv))
-            exit(0)
-        _arguments['history'].add(' '.join(argv))
+        _history = History(_arguments['config'].get('history', 'file'))
+        _history.add(' '.join([exe]+argv[1:]))
         _debug = _arguments['debug'].value
         _help = _arguments['help'].value
         _verbose = _arguments['verbose'].value
index f0476f5..71865aa 100644 (file)
@@ -205,8 +205,7 @@ _arguments = dict(config = _config_arg, help = Argument(0, 'Show help message',
     silent = FlagArgument('Do not output anything', ('-s', '--silent')),
     verbose = FlagArgument('More info at response', ('-v', '--verbose')),
     version = VersionArgument('Print current version', ('-V', '--version')),
-    options = CmdLineConfigArgument(_config_arg, 'Override a config value', ('-o', '--options')),
-    history = HistoryArgument('Show user (prefixed) history', '--history')
+    options = CmdLineConfigArgument(_config_arg, 'Override a config value', ('-o', '--options'))
 )
 
 def parse_known_args(parser):
index 1035f5b..b165f15 100644 (file)
@@ -37,7 +37,7 @@ from kamaki.cli.errors import CLIError, raiseCLIError
 from kamaki.cli.utils import format_size, print_dict, pretty_keys, print_list
 from kamaki.cli.argument import FlagArgument, ValueArgument, IntArgument
 #set_api_description('store', 'Pithos+ storage commands')
-API_DESCRIPTION = {'store':'Pithos+ storage commands'}
+API_DESCRIPTION = dict(store='Pithos+ storage commands')
 from kamaki.clients.pithos import PithosClient, ClientError
 from colors import bold
 from sys import stdout, exit
index 2ea4ee2..3ecfb59 100644 (file)
@@ -60,6 +60,10 @@ DEFAULTS = {
     'config': {
         'cli': 'config_cli',
         'description': 'Configuration commands'
+    },
+    'history':{
+        'cli':'history_cli',
+        'file':'.kamaki.history'
     }
 }