From c667eee570492fd2a382f5a69acdb4aa121fb7de Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Thu, 8 Nov 2012 12:26:54 +0530 Subject: [PATCH] cli: make commands pipe-able as on bash, on the shell Makes commands pipe-able like bash. Example while inside shell: > list virtualmachines | grep id > list accounts | more Signed-off-by: Rohit Yadav --- tools/cli/cloudmonkey/cloudmonkey.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/cli/cloudmonkey/cloudmonkey.py b/tools/cli/cloudmonkey/cloudmonkey.py index 7a42b0b91ec..83bd8c1c6a9 100644 --- a/tools/cli/cloudmonkey/cloudmonkey.py +++ b/tools/cli/cloudmonkey/cloudmonkey.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/python # -*- coding: utf-8 -*- # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file @@ -428,7 +428,13 @@ def main(): if '--help' in args: self.print_shell(res[2]) return - self.default(res[0] + " " + args_partition[2]) + if '|' in args: + 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)) + else: + self.default(res[0] + " " + args_partition[2]) return grammar_closure grammar_handler = add_grammar(rule)