[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] qmp-shell: Fix example with objects as values
From: |
Cleber Rosa |
Subject: |
Re: [Qemu-devel] [PATCH] qmp-shell: Fix example with objects as values |
Date: |
Fri, 11 Jan 2019 09:37:47 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 |
On 1/8/19 7:33 AM, Anthony PERARD wrote:
> The example shown that is suppose to let a user passes an object/array as
> argument doesn't work. The quotes get removed by shlex.split() and then
> both JSON parser complains. Fix the example by adding quotes and add
> examples with boolean and array.
>
> Signed-off-by: Anthony PERARD <address@hidden>
> ---
> scripts/qmp/qmp-shell | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell
> index 770140772d..9937e3c888 100755
> --- a/scripts/qmp/qmp-shell
> +++ b/scripts/qmp/qmp-shell
> @@ -33,7 +33,11 @@
> # key=value pairs also support Python or JSON object literal subset
> notations,
> # without spaces. Dictionaries/objects {} are supported as are arrays [].
> #
> -# example-command arg-name1={'key':'value','obj'={'prop':"value"}}
Yes, I can replicate that with a command such as:
(QEMU) object-add qom-type="rng-random" id="rng1" props={"filename":
"/dev/hwrng"}
That results in:
Error while parsing command line: Expected a key=value pair, got
'/dev/hwrng}'
command format: <command-name> [arg-name1=arg1] ... [arg-nameN=argN]
> +# JSON:
> +# example-command arg-name1='{"key":"value","obj":{"prop":"value"}}'
> +# example-command arg-name1='{"key":"value","obj":[1,true,"three"]}'
The usage fix is to have the dictionary quoted, indeed:
(QEMU) object-add qom-type="rng-random" id="rng4" props="{'filename':
'/dev/hwrng'}"
{"return": {}}
> +# free style:
> +# example-command arg-name1="{'key':'value',\"obj\":[1,True,\"three\"]}"
I just find the "free style" confusing... IMO how to be more creative
about escaping is optional, and adds noise to the most common use case.
Thanks,
- Cleber.
> #
> # Both JSON and Python formatting should work, including both styles of
> # string literal quotes. Both paradigms of literal values should work,
>
--
Cleber Rosa
[ Sr Software Engineer - Virtualization Team - Red Hat ]
[ Avocado Test Framework - avocado-framework.github.io ]
[ 7ABB 96EB 8B46 B94D 5E0F E9BB 657E 8D33 A5F2 09F3 ]