qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Akihiko Odaki <akihiko.odaki@daynix.com>
Cc: "Jason Wang" <jasowang@redhat.com>,
	"Dmitry Fleytman" <dmitry.fleytman@gmail.com>,
	"Sriram Yagnaraman" <sriram.yagnaraman@ericsson.com>,
	"Luigi Rizzo" <rizzo@iet.unipi.it>,
	"Giuseppe Lettieri" <g.lettieri@iet.unipi.it>,
	"Vincenzo Maffione" <v.maffione@gmail.com>,
	"Andrew Melnychenko" <andrew@daynix.com>,
	"Yuri Benditovich" <yuri.benditovich@daynix.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Eduardo Habkost" <eduardo@habkost.net>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Michael Roth" <michael.roth@amd.com>,
	"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Yanan Wang" <wangyanan55@huawei.com>,
	"Zhao Liu" <zhao1.liu@intel.com>, "Lei Yang" <leiyang@redhat.com>,
	"BALATON Zoltan" <balaton@eik.bme.hu>,
	qemu-devel@nongnu.org, devel@daynix.com
Subject: Re: [PATCH] qom: Use command line syntax for default values in help
Date: Thu, 20 Feb 2025 10:39:49 -0500	[thread overview]
Message-ID: <20250220103935-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20250207-bool-v1-1-5749d5d6df24@daynix.com>

On Fri, Feb 07, 2025 at 02:53:43PM +0900, Akihiko Odaki wrote:
> object_property_help() uses the conventional command line syntax instead
> of the JSON syntax. In particular,
> - Key-value pairs are written in the command line syntax.
> - bool description passed to the function says on/off instead of
>   true/false.
> 
> However, there is one exception: default values are formatted into JSON.
> While the command line and JSON syntaxes are consistent in many cases,
> there are two types where they disagree:
> 
> string: The command line syntax omits quotes while JSON requires them.
> 
> bool: JSON only accepts true/false for bool but the command line syntax
>       accepts on/off too, and on/off are also more popular than
>       true/false. For example, the docs directory has 2045 "on"
>       occurances while it has only 194 "true" occurances.
>       on/off are also accepted by OnOffAuto so users do not have to
>       remember the type is bool or OnOffAuto to use the values.
> 
> Omit quotes for strings and use on/off for bools when formatting
> default values for better consistency.
> 
> Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>

Reviewed-by: Michael S. Tsirkin <mst@redhat.com>




> ---
>  qom/object_interfaces.c | 24 +++++++++++++++++++++---
>  1 file changed, 21 insertions(+), 3 deletions(-)
> 
> diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
> index 1a6f29c053e45bf5da5252f6ac1dfa4e85627f9f..f2450f8099c366864b56940e19c6a4bcc0d5e3a9 100644
> --- a/qom/object_interfaces.c
> +++ b/qom/object_interfaces.c
> @@ -4,9 +4,11 @@
>  #include "qapi/error.h"
>  #include "qapi/qapi-visit-qom.h"
>  #include "qapi/qmp/qobject.h"
> +#include "qapi/qmp/qbool.h"
>  #include "qapi/qmp/qdict.h"
>  #include "qapi/qmp/qerror.h"
>  #include "qapi/qmp/qjson.h"
> +#include "qapi/qmp/qstring.h"
>  #include "qapi/qobject-input-visitor.h"
>  #include "qapi/qobject-output-visitor.h"
>  #include "qom/object_interfaces.h"
> @@ -177,9 +179,25 @@ char *object_property_help(const char *name, const char *type,
>          g_string_append(str, description);
>      }
>      if (defval) {
> -        g_autofree char *def_json = g_string_free(qobject_to_json(defval),
> -                                                  false);
> -        g_string_append_printf(str, " (default: %s)", def_json);
> +        g_autofree char *def_json = NULL;
> +        const char *def;
> +
> +        switch (qobject_type(defval)) {
> +        case QTYPE_QSTRING:
> +            def = qstring_get_str(qobject_to(QString, defval));
> +            break;
> +
> +        case QTYPE_QBOOL:
> +            def = qbool_get_bool(qobject_to(QBool, defval)) ? "on" : "off";
> +            break;
> +
> +        default:
> +            def_json = g_string_free(qobject_to_json(defval), false);
> +            def = def_json;
> +            break;
> +        }
> +
> +        g_string_append_printf(str, " (default: %s)", def);
>      }
>  
>      return g_string_free(str, false);
> 
> ---
> base-commit: 7433709a147706ad7d1956b15669279933d0f82b
> change-id: 20250207-bool-967267fd0a25
> 
> Best regards,
> -- 
> Akihiko Odaki <akihiko.odaki@daynix.com>



      parent reply	other threads:[~2025-02-20 15:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-07  5:53 [PATCH] qom: Use command line syntax for default values in help Akihiko Odaki
2025-02-14 15:18 ` Markus Armbruster
2025-02-14 15:47 ` Paolo Bonzini
2025-02-20 15:39 ` Michael S. Tsirkin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250220103935-mutt-send-email-mst@kernel.org \
    --to=mst@redhat.com \
    --cc=akihiko.odaki@daynix.com \
    --cc=andrew@daynix.com \
    --cc=armbru@redhat.com \
    --cc=balaton@eik.bme.hu \
    --cc=berrange@redhat.com \
    --cc=devel@daynix.com \
    --cc=dmitry.fleytman@gmail.com \
    --cc=eduardo@habkost.net \
    --cc=g.lettieri@iet.unipi.it \
    --cc=jasowang@redhat.com \
    --cc=leiyang@redhat.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=michael.roth@amd.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rizzo@iet.unipi.it \
    --cc=sriram.yagnaraman@ericsson.com \
    --cc=v.maffione@gmail.com \
    --cc=wangyanan55@huawei.com \
    --cc=yuri.benditovich@daynix.com \
    --cc=zhao1.liu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).