You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bh...@apache.org on 2013/01/24 23:48:08 UTC

[2/2] git commit: cli: fix cloudmonkey's pipe-ability

Updated Branches:
  refs/heads/master 531c2f030 -> 6f90a86b1


cli: fix cloudmonkey's pipe-ability

Signed-off-by: Rohit Yadav <bh...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/6f90a86b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/6f90a86b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/6f90a86b

Branch: refs/heads/master
Commit: 6f90a86b13ae91441870a008e1e2ff0adc3c26a3
Parents: 71257d6
Author: Rohit Yadav <bh...@apache.org>
Authored: Thu Jan 24 14:47:45 2013 -0800
Committer: Rohit Yadav <bh...@apache.org>
Committed: Thu Jan 24 14:47:45 2013 -0800

----------------------------------------------------------------------
 tools/cli/cloudmonkey/cloudmonkey.py |   30 ++++++++++++++++++++--------
 1 files changed, 21 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6f90a86b/tools/cli/cloudmonkey/cloudmonkey.py
----------------------------------------------------------------------
diff --git a/tools/cli/cloudmonkey/cloudmonkey.py b/tools/cli/cloudmonkey/cloudmonkey.py
index ace6a8b..eadf23f 100644
--- a/tools/cli/cloudmonkey/cloudmonkey.py
+++ b/tools/cli/cloudmonkey/cloudmonkey.py
@@ -75,7 +75,8 @@ class CloudMonkeyShell(cmd.Cmd, object):
     # datastructure {'verb': {cmd': ['api', [params], doc, required=[]]}}
     cache_verbs = precached_verbs
 
-    def __init__(self):
+    def __init__(self, pname):
+        self.program_name = pname
         if os.path.exists(self.config_file):
             config = self.read_config()
         else:
@@ -307,7 +308,19 @@ class CloudMonkeyShell(cmd.Cmd, object):
             return None
         return api_mod
 
+    def pipe_runner(self, args):
+        if args.find(' |') > -1:
+            pname = self.program_name
+            if '.py' in pname:
+                pname = "python " + pname
+            self.do_shell("%s %s" % (pname, args))
+            return True
+        return False
+
     def default(self, args):
+        if self.pipe_runner(args):
+            return
+
         lexp = shlex.shlex(args.strip())
         lexp.whitespace = " "
         lexp.whitespace_split = True
@@ -506,22 +519,21 @@ def main():
     for rule in grammar:
         def add_grammar(rule):
             def grammar_closure(self, args):
-                if '|' in args:  # FIXME: Consider parsing issues
-                    prog_name = sys.argv[0]
-                    if '.py' in prog_name:
-                        prog_name = "python " + prog_name
-                    self.do_shell("%s %s %s" % (prog_name, rule, args))
+                if self.pipe_runner("%s %s" % (rule, args)):
                     return
                 try:
                     args_partition = args.partition(" ")
                     res = self.cache_verbs[rule][args_partition[0]]
+                    cmd = res[0]
+                    helpdoc = res[2]
+                    args = args_partition[2]
                 except KeyError, e:
                     self.print_shell("Error: invalid %s api arg" % rule, e)
                     return
                 if ' --help' in args or ' -h' in args:
-                    self.print_shell(res[2])
+                    self.print_shell(helpdoc)
                     return
-                self.default(res[0] + " " + args_partition[2])
+                self.default("%s %s" % (cmd, args))
             return grammar_closure
 
         grammar_handler = add_grammar(rule)
@@ -529,7 +541,7 @@ def main():
         grammar_handler.__name__ = 'do_' + rule
         setattr(self, grammar_handler.__name__, grammar_handler)
 
-    shell = CloudMonkeyShell()
+    shell = CloudMonkeyShell(sys.argv[0])
     if len(sys.argv) > 1:
         shell.onecmd(' '.join(sys.argv[1:]))
     else: