Interactive shell (without functionality ftm)
authorStavros Sachtouris <saxtouri@admin.grnet.gr>
Wed, 10 Oct 2012 13:58:51 +0000 (16:58 +0300)
committerStavros Sachtouris <saxtouri@admin.grnet.gr>
Wed, 10 Oct 2012 13:58:51 +0000 (16:58 +0300)
kamaki/cli/__init__.py
kamaki/cli/command_tree.py
setup.py

index 24ae96b..d03db81 100644 (file)
@@ -58,6 +58,7 @@ 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
+import cmd
 
 cmd_spec_locations = [
     'kamaki.cli.commands',
@@ -316,3 +317,32 @@ def one_command():
         _print_error_message(err, verbose=_verbose)
         exit(1)
 
+class Shell(cmd.Cmd):
+    """Kamaki interactive shell"""
+
+    def greet(self, version):
+        print('kamaki v%s - Interactive Shell\n\t(exit or ^D to exit)\n'%version)
+    def set_prompt(self, new_prompt):
+        self.prompt = '[%s]:'%new_prompt
+
+    def do_exit(self, line):
+        return True
+
+shell = None
+
+def _start_shell():
+    shell = Shell()
+    shell.set_prompt(basename(argv[0]))
+    from kamaki import __version__ as version
+    shell.greet(version)
+    shell.do_EOF = shell.do_exit
+    shell.cmdloop()
+
+def shell():
+    _start_shell()
+
+def main():
+    if len(argv) <= 1:
+        shell()
+    else:
+        one_command()
\ No newline at end of file
index e3cdfb6..23f630a 100644 (file)
@@ -237,10 +237,11 @@ class Shell(cmd.Cmd):
        def do_EOF(self, line):
                return True
 
-#sh = Shell()
-#sh.prompt = 'lala_$ '
-#sh.cmdloop()
-
-#import sys
-#sh.onecmd(' '.join(sys.argv[1:]))
-#test_CommandTree()
\ No newline at end of file
+if __name__ == '__main__':
+       sh = Shell()
+       sh.prompt = 'lala_$ '
+       sh.cmdloop()
+
+       #import sys
+       #sh.onecmd(' '.join(sys.argv[1:]))
+       #test_CommandTree()
\ No newline at end of file
index 9690802..22094cb 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -54,7 +54,7 @@ setup(
     packages=['kamaki', 'kamaki.cli', 'kamaki.clients', 'kamaki.clients.connection', 'kamaki.cli.commands'],
     include_package_data=True,
     entry_points={
-        'console_scripts': ['kamaki = kamaki.cli:one_command']
+        'console_scripts': ['kamaki = kamaki.cli:main']
     },
     install_requires=required
 )