diff mbox series

[v3,02/38] qmp-shell: learn to send commands with quoted arguments

Message ID 20180326150916.9602-3-marcandre.lureau@redhat.com
State New
Headers show
Series RFC: monitor: add asynchronous command type | expand

Commit Message

Marc-André Lureau March 26, 2018, 3:08 p.m. UTC
Use shlex to split the CLI command, respecting quoted arguments, and
also comments. This allows to call for ex:

(QEMU) human-monitor-command command-line="screendump /dev/null"
{"execute": "human-monitor-command", "arguments": {"command-line": "screendump /dev/null"}}

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 scripts/qmp/qmp-shell | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Eduardo Habkost March 26, 2018, 6:26 p.m. UTC | #1
On Mon, Mar 26, 2018 at 05:08:40PM +0200, Marc-André Lureau wrote:
> Use shlex to split the CLI command, respecting quoted arguments, and
> also comments. This allows to call for ex:
> 
> (QEMU) human-monitor-command command-line="screendump /dev/null"
> {"execute": "human-monitor-command", "arguments": {"command-line": "screendump /dev/null"}}
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Wonderful.

Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
diff mbox series

Patch

diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell
index be449de621..af7033c765 100755
--- a/scripts/qmp/qmp-shell
+++ b/scripts/qmp/qmp-shell
@@ -73,6 +73,7 @@  import sys
 import os
 import errno
 import atexit
+import shlex
 
 class QMPCompleter(list):
     def complete(self, text, state):
@@ -218,7 +219,7 @@  class QMPShell(qmp.QEMUMonitorProtocol):
 
             < command-name > [ arg-name1=arg1 ] ... [ arg-nameN=argN ]
         """
-        cmdargs = cmdline.split()
+        cmdargs = shlex.split(cmdline)
 
         # Transactional CLI entry/exit:
         if cmdargs[0] == 'transaction(':