From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53160) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhYhg-00035g-RH for qemu-devel@nongnu.org; Tue, 15 Aug 2017 06:04:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dhYhc-00021d-PQ for qemu-devel@nongnu.org; Tue, 15 Aug 2017 06:04:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33994) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dhYhc-00021F-HP for qemu-devel@nongnu.org; Tue, 15 Aug 2017 06:04:00 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6BD78C0546F8 for ; Tue, 15 Aug 2017 10:03:59 +0000 (UTC) From: Markus Armbruster References: <20170808203935.30021-1-ehabkost@redhat.com> <20170808203935.30021-5-ehabkost@redhat.com> Date: Tue, 15 Aug 2017 12:03:53 +0200 In-Reply-To: <20170808203935.30021-5-ehabkost@redhat.com> (Eduardo Habkost's message of "Tue, 8 Aug 2017 17:39:34 -0300") Message-ID: <87fuctp2pi.fsf@dusky.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH for-2.11 v2 4/5] qmp-shell: Accept QMP command as argument List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eduardo Habkost Cc: qemu-devel@nongnu.org, John Snow , Stefan Hajnoczi Eduardo Habkost writes: Suggest to insert here: If additional arguments QMP-COMMAND ARG=VAL... are given, run just that QMP command instead of the REPL. Question: is this limited to simple arguments? If no, how would I write an object argument? For instance, how would I do { "execute": "blockdev-add", "arguments": { "node-name": "foo", "driver": "nbd", "server": { "type": "inet", "host": "localhost", "port": "12345" } } } ? > This is useful for testing QMP commands in scripts. > > Example usage, combined with 'jq' for filtering the results: > > $ ./scripts/qmp/qmp-shell /tmp/qmp qom-list path=/ | jq -r .return[].name > machine > type > chardevs > backend What's jq? > $ Let's drop this line. > > Signed-off-by: Eduardo Habkost > --- > Changes v1 -> v2: > * Rewritten using optparse module > --- > scripts/qmp/qmp-shell | 14 +++++++++----- > 1 file changed, 9 insertions(+), 5 deletions(-) > > diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell > index 4b9a420..4b7374e 100755 > --- a/scripts/qmp/qmp-shell > +++ b/scripts/qmp/qmp-shell > @@ -400,7 +400,7 @@ def die(msg): > > def main(): > parser = optparse.OptionParser(description='QMP shell utility') > - parser.set_usage("%prog [options] | ") > + parser.set_usage("%prog [options] | [COMMAND [ARG=VALUE]...]") > parser.add_option('-v', action='store_true', dest='verbose', > help='Verbose (echo command sent and received)') > parser.add_option('-p', action='store_true', dest='pretty', > @@ -411,10 +411,11 @@ def main(): > default=True, help='Skip negotiate (for qemu-ga)') > opts,args = parser.parse_args() > > - if len(args) != 1: > + if len(args) < 1: > parser.print_help(sys.stderr) > sys.exit(1) > addr = args[0] > + cmdargs = args[1:] > > try: > if opts.hmp: > @@ -433,10 +434,13 @@ def main(): > except qemu.error: > die('Could not connect to %s' % addr) > > - qemu.show_banner() > qemu.set_verbosity(opts.verbose) > - while qemu.read_exec_command(qemu.get_prompt()): > - pass > + if len(cmdargs): Superfluous len(). > + qemu.execute_cmdargs(cmdargs) > + else: > + qemu.show_banner() > + while qemu.read_exec_command(qemu.get_prompt()): > + pass > qemu.close() > > if __name__ == '__main__':