Patchwork [V16,6/7] query-command-line-options outputs def_value_str

login
register
mail settings
Submitter Robert Wang
Date June 18, 2013, 9:31 a.m.
Message ID <1371547919-15654-7-git-send-email-wdongxu@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/252202/
State New
Headers show

Comments

Robert Wang - June 18, 2013, 9:31 a.m.
QMP command query-command-line-options shows details information of
parameters, since added def_value_str, also output it in the QMP
command.

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
---
 qapi-schema.json   | 5 ++++-
 qmp-commands.hx    | 2 ++
 util/qemu-config.c | 4 ++++
 3 files changed, 10 insertions(+), 1 deletion(-)
Eric Blake - July 10, 2013, 7:56 p.m.
On 06/18/2013 03:31 AM, Dong Xu Wang wrote:
> QMP command query-command-line-options shows details information of
> parameters, since added def_value_str, also output it in the QMP
> command.
> 
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> ---
>  qapi-schema.json   | 5 ++++-
>  qmp-commands.hx    | 2 ++
>  util/qemu-config.c | 4 ++++
>  3 files changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/qapi-schema.json b/qapi-schema.json
> index a80ee40..a9202b0 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -3541,12 +3541,15 @@
>  #
>  # @help: #optional human readable text string, not suitable for parsing.
>  #
> +# @def_value_str: #optional default value string for the parameter

Andreas called one aspect - please add '(since 1.6)'.

New QMP interfaces favor '-' over '_', and we also favor full words
rather than abbreviations.  Furthermore, since this parameter is already
typed as a string, I think the _str suffix is redundant.  I think it is
sufficient to just name it 'default', as in:

# @default: #optional string representation of the default used
#           if the option is omitted

> +++ b/qmp-commands.hx
> @@ -2521,6 +2521,8 @@ Each array entry contains the following:
>                or 'size')
>      - "help": human readable description of the parameter
>                (json-string, optional)
> +    - "def_value_str": default value string for the parameter
> +              (json-string, optional)
>  
>  Example:

Is it worth picking an example that actually shows a default value?  But
I won't insist.

>  
> diff --git a/util/qemu-config.c b/util/qemu-config.c
> index a59568d..538d743 100644
> --- a/util/qemu-config.c
> +++ b/util/qemu-config.c
> @@ -67,6 +67,10 @@ static CommandLineParameterInfoList *query_option_descs(const QemuOptDesc *desc)
>              info->has_help = true;
>              info->help = g_strdup(desc[i].help);
>          }
> +        if (desc[i].def_value_str) {
> +            info->has_def_value_str = true;
> +            info->def_value_str = g_strdup(desc[i].def_value_str);

Of course, if you follow my naming suggestion, this would be
desc[i].q_default (or whatever QAPI code generation munges it to),
rather than desc[i].default, thanks to being a C keyword :)

Patch

diff --git a/qapi-schema.json b/qapi-schema.json
index a80ee40..a9202b0 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3541,12 +3541,15 @@ 
 #
 # @help: #optional human readable text string, not suitable for parsing.
 #
+# @def_value_str: #optional default value string for the parameter
+#
 # Since 1.5
 ##
 { 'type': 'CommandLineParameterInfo',
   'data': { 'name': 'str',
             'type': 'CommandLineParameterType',
-            '*help': 'str' } }
+            '*help': 'str',
+            '*def_value_str': 'str'} }
 
 ##
 # @CommandLineOptionInfo:
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 8cea5e5..13430e3 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -2521,6 +2521,8 @@  Each array entry contains the following:
               or 'size')
     - "help": human readable description of the parameter
               (json-string, optional)
+    - "def_value_str": default value string for the parameter
+              (json-string, optional)
 
 Example:
 
diff --git a/util/qemu-config.c b/util/qemu-config.c
index a59568d..538d743 100644
--- a/util/qemu-config.c
+++ b/util/qemu-config.c
@@ -67,6 +67,10 @@  static CommandLineParameterInfoList *query_option_descs(const QemuOptDesc *desc)
             info->has_help = true;
             info->help = g_strdup(desc[i].help);
         }
+        if (desc[i].def_value_str) {
+            info->has_def_value_str = true;
+            info->def_value_str = g_strdup(desc[i].def_value_str);
+        }
 
         entry = g_malloc0(sizeof(*entry));
         entry->value = info;