From: Eric Blake <eblake@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>, qemu-block@nongnu.org
Cc: mreitz@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com
Subject: Re: [PATCH 1/4] keyval: Parse help options
Date: Tue, 29 Sep 2020 12:46:55 -0500 [thread overview]
Message-ID: <b28cad72-d344-78fa-fc07-b4a6a63fbc50@redhat.com> (raw)
In-Reply-To: <20200929172649.158086-2-kwolf@redhat.com>
[-- Attachment #1.1: Type: text/plain, Size: 3196 bytes --]
On 9/29/20 12:26 PM, Kevin Wolf wrote:
> This adds a new parameter 'help' to keyval_parse() that enables parsing
> of help options. If NULL is passed, the function behaves the same as
> before. But if a bool pointer is given, it contains the information
> whether an option "help" without value was given (which would otherwise
> either result in an error or be interpreted as the value for an implied
> key).
>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
> +++ b/util/keyval.c
Might be nice to see this before the testsuite changes by tweaking the
git orderfile.
> @@ -166,7 +166,7 @@ static QObject *keyval_parse_put(QDict *cur,
> * On failure, return NULL.
> */
> static const char *keyval_parse_one(QDict *qdict, const char *params,
> - const char *implied_key,
> + const char *implied_key, bool *help,
> Error **errp)
> {
> const char *key, *key_end, *s, *end;
> @@ -179,6 +179,16 @@ static const char *keyval_parse_one(QDict *qdict, const char *params,
>
> key = params;
> len = strcspn(params, "=,");
> +
> + if (help && key[len] != '=' && !strncmp(key, "help", len)) {
What if the user typed "help,," to get "help," as the value of the
implied key?
> + *help = true;
> + s = key + len;
> + if (key[len] != '\0') {
> + s++;
> + }
> + return s;
> + }
> +
> if (implied_key && len && key[len] != '=') {
> /* Desugar implied key */
> key = implied_key;
> @@ -388,21 +398,33 @@ static QObject *keyval_listify(QDict *cur, GSList *key_of_cur, Error **errp)
>
> /*
> * Parse @params in QEMU's traditional KEY=VALUE,... syntax.
> + *
> * If @implied_key, the first KEY= can be omitted. @implied_key is
> * implied then, and VALUE can't be empty or contain ',' or '='.
> + *
> + * If @help is given, an option "help" without a value isn't added to
> + * the resulting dictionary, but instead sets @help to true. If no
> + * help option is found, @help is false on return. All other options
> + * are parsed and returned normally so that context specific help can
> + * be printed.
> + *
> * On success, return a dictionary of the parsed keys and values.
> * On failure, store an error through @errp and return NULL.
> */
> QDict *keyval_parse(const char *params, const char *implied_key,
> - Error **errp)
> + bool *help, Error **errp)
> {
> QDict *qdict = qdict_new();
> QObject *listified;
> const char *s;
>
> + if (help) {
> + *help = false;
> + }
> +
> s = params;
> while (*s) {
> - s = keyval_parse_one(qdict, s, implied_key, errp);
> + s = keyval_parse_one(qdict, s, implied_key, help, errp);
> if (!s) {
> qobject_unref(qdict);
> return NULL;
>
I like it, but wonder if you are missing one corner case.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2020-09-29 17:49 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-29 17:26 [PATCH 0/4] qemu-storage-daemon: Remove QemuOpts from --object parser Kevin Wolf
2020-09-29 17:26 ` [PATCH 1/4] keyval: Parse help options Kevin Wolf
2020-09-29 17:46 ` Eric Blake [this message]
2020-09-30 13:04 ` Kevin Wolf
2020-09-30 13:42 ` Eric Blake
2020-09-30 14:56 ` Kevin Wolf
2020-10-09 14:36 ` Markus Armbruster
2020-09-29 17:26 ` [PATCH 2/4] qom: Factor out helpers from user_creatable_print_help() Kevin Wolf
2020-09-29 17:51 ` Eric Blake
2020-09-29 17:26 ` [PATCH 3/4] qom: Add user_creatable_print_help_from_qdict() Kevin Wolf
2020-09-29 17:53 ` Eric Blake
2020-09-29 17:26 ` [PATCH 4/4] qemu-storage-daemon: Remove QemuOpts from --object parser Kevin Wolf
2020-09-29 17:54 ` Eric Blake
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=b28cad72-d344-78fa-fc07-b4a6a63fbc50@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/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).