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

Marc-André Lureau posted 38 patches 7 years, 10 months ago
[Qemu-devel] [PATCH v3 02/38] qmp-shell: learn to send commands with quoted arguments
Posted by Marc-André Lureau 7 years, 10 months ago
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(-)

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(':
-- 
2.17.0.rc1.1.g4c4f2b46a3


Re: [Qemu-devel] [PATCH v3 02/38] qmp-shell: learn to send commands with quoted arguments
Posted by Eduardo Habkost 7 years, 10 months ago
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>

-- 
Eduardo