From: Kevin Wolf <kwolf@redhat.com>
To: Michael Tokarev <mjt@tls.msk.ru>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org
Subject: Re: [PATCH 05/27] qemu-img: create: refresh options/--help
Date: Tue, 5 Nov 2024 20:57:56 +0100 [thread overview]
Message-ID: <Zyp4xJcwf-gwOacy@redhat.com> (raw)
In-Reply-To: <20240927061121.573271-6-mjt@tls.msk.ru>
Am 27.09.2024 um 08:10 hat Michael Tokarev geschrieben:
> Create helper function cmd_help() to display command-specific
> help text, and use it to print --help for 'create' subcommand.
>
> Add missing long options (eg --format) in img_create().
>
> Remove usage of missing_argument()/unrecognized_option() in
> img_create().
>
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> ---
> qemu-img.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++-------
> 1 file changed, 61 insertions(+), 8 deletions(-)
>
> diff --git a/qemu-img.c b/qemu-img.c
> index e8234104e5..7ed5e6d1a8 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -132,6 +132,32 @@ void unrecognized_option(const char *option)
> error_exit("qemu-img", "unrecognized option '%s'", option);
> }
>
> +/*
> + * Print --help output for a command and exit.
> + * syntax and description are multi-line with trailing EOL
> + * (to allow easy extending of the text)
> + * syntax has each subsequent line indented by 8 chars.
> + * desrciption is indented by 2 chars for argument on each own line,
s/desrciption/description/
I would also suggest writing @syntax and @description as we do in other
places to indicate that we're talking about parameter names here rather
than normal English words.
> + * and with 5 chars for argument description (like -h arg below).
> + */
> +static G_NORETURN
> +void cmd_help(const img_cmd_t *ccmd,
> + const char *syntax, const char *arguments)
> +{
> + printf(
> +"Usage:\n"
> +"\n"
> +" %s %s %s"
> +"\n"
> +"Arguments:\n"
> +" -h, --help\n"
> +" print this help and exit\n"
> +"%s\n",
> + "qemu-img", ccmd->name,
> + syntax, arguments);
The last two lines should easily fit on a single one.
> + exit(EXIT_SUCCESS);
> +}
> +
> /* Please keep in synch with docs/tools/qemu-img.rst */
> static G_NORETURN
> void help(void)
> @@ -530,23 +556,48 @@ static int img_create(const img_cmd_t *ccmd, int argc, char **argv)
> for(;;) {
> static const struct option long_options[] = {
> {"help", no_argument, 0, 'h'},
> + {"quiet", no_argument, 0, 'q'},
> {"object", required_argument, 0, OPTION_OBJECT},
> + {"format", required_argument, 0, 'f'},
> + {"backing", required_argument, 0, 'b'},
> + {"backing-format", required_argument, 0, 'F'},
> + {"backing-unsafe", no_argument, 0, 'u'},
> + {"options", required_argument, 0, 'o'},
> {0, 0, 0, 0}
> };
> - c = getopt_long(argc, argv, ":F:b:f:ho:qu",
> + c = getopt_long(argc, argv, "F:b:f:ho:qu",
> long_options, NULL);
Can we please keep the same order in long_options and in the options
string?
> if (c == -1) {
> break;
> }
> switch(c) {
> - case ':':
> - missing_argument(argv[optind - 1]);
> - break;
> - case '?':
> - unrecognized_option(argv[optind - 1]);
> - break;
> case 'h':
> - help();
> + cmd_help(ccmd,
Is this new help text copied from somewhere or is it written from
scratch? I couldn't find the source if it was copied, so I'll treat it
as new and compare it only with the generic help text and the man page.
> +"[-f FMT] [-o FMT_OPTS] [-b BACKING_FILENAME [-F BACKING_FMT]]\n"
> +" [--object OBJDEF] [-u] FILENAME [SIZE[bkKMGTPE]]\n"
This is yet another order. It also seems to miss -q.
The existing documentation has this:
create [--object OBJECTDEF] [-q] [-f FMT] [-b BACKING_FILE [-F BACKING_FMT]] [-u] [-o OPTIONS] FILENAME [SIZE]
Which is a fourth different order and description. It would probably be
good to consolidate on a single option and way to name parameter
placeholders.
> +,
> +" -q, --quiet\n"
> +" quiet operations\n"
> +" -f, --format FMT\n"
> +" specifies format of the new image, default is raw\n"
s/format/the format/
I would suggest "(default: raw)" as the format to use for defaults. It's
a bit easier to read when it's clearly not part of the sentence.
> +" -o, --options FMT_OPTS\n"
> +" format-specific options ('-o list' for list)\n"
Do you mean '-o help'?
> +" -b, --backing BACKING_FILENAME\n"
> +" stack new image on top of BACKING_FILENAME\n"
> +" (for formats which support stacking)\n"
"stacking" isn't terminology we use elsewhere. Maybe "create image as a
copy-on-write overlay on top of BACKING_FILENAME (not supported by all
formats)"?
Not sure if it's worth having the parenthesis at all, many options of
qemu-img will only work with some formats.
> +" -F, --backing-format BACKING_FMT\n"
> +" specify format of BACKING_FILENAME\n"
-f said "specifies" (which sounds a bit better to me), let's stay
consistent. Same s/format/the format/, too.
> +" -u, --backing-unsafe\n"
> +" do not fail if BACKING_FMT can not be read\n"
BACKING_FILENAME?
Maybe "don't try to open BACKING_FILENAME for verification"?
> +" --object OBJDEF\n"
> +" QEMU user-creatable object (eg encryption key)\n"
s/eg/e.g./
Most other options start with a verb. Maybe "define a user-creatable
object"?
> +" FILENAME\n"
> +" image file to create. It will be overridden if exists\n"
overwritten?
If you have one full stop in it, I think we should have one at the end,
too: "...if it exists.\n"
> +" SIZE\n"
> +" image size with optional suffix (multiplies in 1024)\n"
Powers of 1024?
The existing help is a bit more explicit about the supported suffixes:
" 'size' is the disk image size in bytes. Optional suffixes\n"
" 'k' or 'K' (kilobyte, 1024), 'M' (megabyte, 1024k), 'G' (gigabyte, 1024M),\n"
" 'T' (terabyte, 1024G), 'P' (petabyte, 1024T) and 'E' (exabyte, 1024P) are\n"
" supported. 'b' is ignored.\n"
> +" SIZE is required unless BACKING_IMG is specified,\n"
> +" in which case it will be the same as size of BACKING_IMG\n"
"it will default to the same size as BACKING_IMG"?
> +);
> break;
> case 'F':
> base_fmt = optarg;
> @@ -571,6 +622,8 @@ static int img_create(const img_cmd_t *ccmd, int argc, char **argv)
> case OPTION_OBJECT:
> user_creatable_process_cmdline(optarg);
> break;
> + default:
> + tryhelp(argv[0]);
> }
> }
Kevin
next prev parent reply other threads:[~2024-11-05 19:58 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-27 6:10 [PATCH resend v3 00/27] qemu-img: refersh options and --help handling, cleanups Michael Tokarev
2024-09-27 6:10 ` [PATCH 01/27] qemu-img: measure: convert img_size to signed, simplify handling Michael Tokarev
2024-11-05 19:27 ` Kevin Wolf
2024-09-27 6:10 ` [PATCH 02/27] qemu-img: create: " Michael Tokarev
2024-11-05 19:27 ` Kevin Wolf
2024-09-27 6:10 ` [PATCH 03/27] qemu-img: global option processing and error printing Michael Tokarev
2024-11-05 19:29 ` Kevin Wolf
2024-09-27 6:10 ` [PATCH 04/27] qemu-img: pass current cmd info into command handlers Michael Tokarev
2024-11-05 19:29 ` Kevin Wolf
2024-09-27 6:10 ` [PATCH 05/27] qemu-img: create: refresh options/--help Michael Tokarev
2024-11-05 19:57 ` Kevin Wolf [this message]
2024-09-27 6:11 ` [PATCH 06/27] qemu-img: factor out parse_output_format() and use it in the code Michael Tokarev
2025-05-13 15:25 ` Kevin Wolf
2024-09-27 6:11 ` [PATCH 07/27] qemu-img: check: refresh options/--help Michael Tokarev
2025-05-13 15:54 ` Kevin Wolf
2025-05-15 6:50 ` Michael Tokarev
2025-05-15 7:53 ` Kevin Wolf
2025-05-31 16:51 ` Michael Tokarev
2025-06-02 10:44 ` Kevin Wolf
2024-09-27 6:11 ` [PATCH 08/27] qemu-img: simplify --repair error message Michael Tokarev
2025-05-13 16:05 ` Kevin Wolf
2024-09-27 6:11 ` [PATCH 09/27] qemu-img: commit: refresh options/--help Michael Tokarev
2025-05-13 16:24 ` Kevin Wolf
2024-09-27 6:11 ` [PATCH 10/27] qemu-img: compare: " Michael Tokarev
2024-09-27 6:11 ` [PATCH 11/27] qemu-img: convert: " Michael Tokarev
2024-09-27 6:11 ` [PATCH 12/27] qemu-img: info: " Michael Tokarev
2024-09-27 6:11 ` [PATCH 13/27] qemu-img: map: " Michael Tokarev
2024-09-27 6:11 ` [PATCH 14/27] qemu-img: snapshot: allow specifying -f fmt Michael Tokarev
2024-09-27 6:11 ` [PATCH 15/27] qemu-img: snapshot: make -l (list) the default, simplify option handling Michael Tokarev
2024-09-27 6:11 ` [PATCH 16/27] qemu-img: snapshot: refresh options/--help Michael Tokarev
2024-09-27 6:11 ` [PATCH 17/27] qemu-img: rebase: " Michael Tokarev
2024-09-27 6:11 ` [PATCH 18/27] qemu-img: resize: do not always eat last argument Michael Tokarev
2024-09-27 6:11 ` [PATCH 19/27] qemu-img: resize: refresh options/--help Michael Tokarev
2024-09-27 6:11 ` [PATCH 20/27] qemu-img: amend: " Michael Tokarev
2024-09-27 6:11 ` [PATCH 21/27] qemu-img: bench: " Michael Tokarev
2024-09-27 6:11 ` [PATCH 22/27] qemu-img: bitmap: " Michael Tokarev
2024-09-27 6:11 ` [PATCH 23/27] qemu-img: dd: " Michael Tokarev
2024-09-27 6:11 ` [PATCH 24/27] qemu-img: measure: " Michael Tokarev
2024-09-27 6:11 ` [PATCH 25/27] qemu-img: implement short --help, remove global help() function Michael Tokarev
2024-09-27 6:11 ` [PATCH 26/27] qemu-img: inline list of supported commands, remove qemu-img-cmds.h include Michael Tokarev
2024-09-27 6:11 ` [PATCH 27/27] qemu-img: extend cvtnum() and use it in more places Michael Tokarev
2024-10-23 6:15 ` [PATCH resend v3 00/27] qemu-img: refersh options and --help handling, cleanups Michael Tokarev
-- strict thread matches above, loose matches on Subject: below --
2024-04-24 8:50 [PATCH " Michael Tokarev
2024-04-24 8:50 ` [PATCH 05/27] qemu-img: create: refresh options/--help Michael Tokarev
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=Zyp4xJcwf-gwOacy@redhat.com \
--to=kwolf@redhat.com \
--cc=mjt@tls.msk.ru \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.