From 1551b982c4f733bd85a72f48c9f7eb9782462ddd Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Wed, 12 Dec 2012 15:21:03 -0800 Subject: [PATCH] cli: Handle command breaks, ctrl+c, don't break the shell - Fix handles shell loop - Handles any control breaks without breaking the shell - Handles ctrl+c to start afresh on the shell Signed-off-by: Rohit Yadav --- tools/cli/cloudmonkey/cloudmonkey.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/cli/cloudmonkey/cloudmonkey.py b/tools/cli/cloudmonkey/cloudmonkey.py index 8ceba4a0a15..250ea68a5f1 100644 --- a/tools/cli/cloudmonkey/cloudmonkey.py +++ b/tools/cli/cloudmonkey/cloudmonkey.py @@ -65,7 +65,7 @@ logger = logging.getLogger(__name__) completions = cloudstackAPI.__all__ -class CloudStackShell(cmd.Cmd): +class CloudStackShell(cmd.Cmd, object): intro = ("☁ Apache CloudStack 🐵 cloudmonkey " + __version__ + ". Type help or ? to list commands.\n") ruler = "=" @@ -133,6 +133,15 @@ class CloudStackShell(cmd.Cmd): def emptyline(self): pass + def cmdloop(self, intro=None): + print self.intro + while True: + try: + super(CloudStackShell, self).cmdloop(intro = "") + self.postloop() + except KeyboardInterrupt: + print("^C") + def print_shell(self, *args): try: for arg in args: @@ -273,7 +282,6 @@ class CloudStackShell(cmd.Cmd): x.partition("=")[2]], args[1:])[x] for x in range(len(args) - 1)) - # FIXME: With precaching, dynamic loading can be removed api_cmd_str = "%sCmd" % api_name api_mod = self.get_api_module(api_name, [api_cmd_str]) if api_mod is None: @@ -466,7 +474,7 @@ class CloudStackShell(cmd.Cmd): """ Quit on Ctrl+d or EOF """ - return True + sys.exit() def main():