From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Michael Tokarev <mjt@tls.msk.ru>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org
Subject: Re: [PATCH 02/23] qemu-img: refresh options/--help for "create" subcommand
Date: Tue, 20 Feb 2024 18:41:21 +0000 [thread overview]
Message-ID: <ZdTyUVIV0obAL1kG@redhat.com> (raw)
In-Reply-To: <43c69e56b65b39da7c9bd878fd9c6fad4f788c1a.1707513011.git.mjt@tls.msk.ru>
On Sat, Feb 10, 2024 at 12:22:23AM +0300, Michael Tokarev wrote:
> Add missing long options (eg --format).
>
> Create helper function cmd_help() to display command-specific
> help text, and use it to print --help for 'create' subcommand.
>
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> ---
> qemu-img.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 44 insertions(+), 1 deletion(-)
>
> diff --git a/qemu-img.c b/qemu-img.c
> index 05f80b6e5b..7edfc56572 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -126,6 +126,25 @@ void unrecognized_option(const img_cmd_t *ccmd, const char *option)
> error_exit(ccmd, "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 starting with \t
> + * desrciption is indented by one char
> + */
> +static G_NORETURN
> +void cmd_help(const img_cmd_t *ccmd,
> + const char *syntax, const char *arguments)
> +{
> + printf("qemu-img %s %s"
I think we want an extra "\n" before & after 'Arguments:'
> + "Arguments:\n"
> + " -h|--help - print this help and exit\n"
> + "%s",
> + ccmd->name, syntax, arguments);
> + exit(EXIT_SUCCESS);
> +}
> +
> /* Please keep in synch with docs/tools/qemu-img.rst */
> static G_NORETURN
> void help(void)
> @@ -524,7 +543,13 @@ 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",
> @@ -540,7 +565,25 @@ static int img_create(const img_cmd_t *ccmd, int argc, char **argv)
> unrecognized_option(ccmd, argv[optind - 1]);
> break;
> case 'h':
> - help();
> + cmd_help(ccmd,
> +"[-f FMT] [-o FMT_OPTS] [-b BACKING_FILENAME [-F BACKING_FMT]]\n"
> +" [--object OBJDEF] [-u] FILENAME [SIZE[bkKMGTPE]]\n"
> +,
> +" -q|--quiet - quiet operations\n"
> +" -f|--format FMT - specifies format of the new image, default is raw\n"
> +" -o|--options FMT_OPTS - format-specific options ('-o list' for list)\n"
> +" -b|--backing BACKING_FILENAME - stack new image on top of BACKING_FILENAME\n"
> +" (for formats which support stacking)\n"
> +" -F|--backing-format BACKING_FMT - specify format of BACKING_FILENAME\n"
> +" -u|--backing-unsafe - do not fail if BACKING_FMT can not be read\n"
> +" --object OBJDEF - QEMU user-creatable object (eg encryption key)\n"
> +" FILENAME - image file to create. It will be overriden if exists\n"
> +" SIZE - image size with optional suffix: 'b' (byte, default), 'k' or\n"
> +" 'K' (kilobyte, 1024b), 'M' (megabyte, 1024K), 'G' (gigabyte, 1024M),\n"
> +" 'T' (terabyte, 1024G), 'P' (petabyte, 1024T), or 'E' (exabyte, 1024P)\n"
> +" SIZE is required unless BACKING_IMG is specified, in which case\n"
> +" it will be the same as size of BACKING_IMG\n"
This comes out as a bit of a wall of dense text.
I think we should have 2 space indent for options, and a further
4 space for continuations, and also put the description on its
own line.
eg so instead of getting:
$ ./build/qemu-img create --help
qemu-img create [-f FMT] [-o FMT_OPTS] [-b BACKING_FILENAME [-F BACKING_FMT]]
[--object OBJDEF] [-u] FILENAME [SIZE[bkKMGTPE]]
Arguments:
-h|--help - print this help and exit
-q|--quiet - quiet operations
-f|--format FMT - specifies format of the new image, default is raw
-o|--options FMT_OPTS - format-specific options ('-o list' for list)
-b|--backing BACKING_FILENAME - stack new image on top of BACKING_FILENAME
(for formats which support stacking)
-F|--backing-format BACKING_FMT - specify format of BACKING_FILENAME
-u|--backing-unsafe - do not fail if BACKING_FMT can not be read
--object OBJDEF - QEMU user-creatable object (eg encryption key)
FILENAME - image file to create. It will be overriden if exists
SIZE - image size with optional suffix: 'b' (byte, default), 'k' or
'K' (kilobyte, 1024b), 'M' (megabyte, 1024K), 'G' (gigabyte, 1024M),
'T' (terabyte, 1024G), 'P' (petabyte, 1024T), or 'E' (exabyte, 1024P)
SIZE is required unless BACKING_IMG is specified, in which case
it will be the same as size of BACKING_IMG
we would get:
$ ./build/qemu-img create --help
qemu-img create [-f FMT] [-o FMT_OPTS] [-b BACKING_FILENAME [-F BACKING_FMT]]
[--object OBJDEF] [-u] FILENAME [SIZE[bkKMGTPE]]
Arguments:
-h|--help
print this help and exit
-q|--quiet
quiet operations
-f|--format FMT
specifies format of the new image, default is raw
-o|--options FMT_OPTS
format-specific options ('-o list' for list)
-b|--backing BACKING_FILENAME
stack new image on top of BACKING_FILENAME
(for formats which support stacking)
-F|--backing-format BACKING_FMT
specify format of BACKING_FILENAME
-u|--backing-unsafe
do not fail if BACKING_FMT can not be read
--object OBJDEF
QEMU user-creatable object (eg encryption key)
FILENAME
image file to create. It will be overriden if exists
SIZE
image size with optional suffix: 'b' (byte, default), 'k' or
'K' (kilobyte, 1024b), 'M' (megabyte, 1024K), 'G' (gigabyte, 1024M),
'T' (terabyte, 1024G), 'P' (petabyte, 1024T), or 'E' (exabyte, 1024P)
SIZE is required unless BACKING_IMG is specified, in which case
it will be the same as size of BACKING_IMG
> +);
> break;
> case 'F':
> base_fmt = optarg;
> --
> 2.39.2
>
>
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2024-02-20 18:42 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-09 21:22 [PATCH 00/23] qemu-img: refersh options and --help handling Michael Tokarev
2024-02-09 21:22 ` [PATCH 01/23] qemu-img: pass current cmd info into command handlers Michael Tokarev
2024-02-20 17:29 ` Daniel P. Berrangé
2024-02-09 21:22 ` [PATCH 02/23] qemu-img: refresh options/--help for "create" subcommand Michael Tokarev
2024-02-20 18:41 ` Daniel P. Berrangé [this message]
2024-02-09 21:22 ` [PATCH 03/23] qemu-img: factor out parse_output_format() and use it in the code Michael Tokarev
2024-02-20 17:38 ` Daniel P. Berrangé
2024-02-09 21:22 ` [PATCH 04/23] qemu-img: refresh options/--help for "check" command Michael Tokarev
2024-02-09 21:22 ` [PATCH 05/23] qemu-img: simplify --repair error message Michael Tokarev
2024-02-20 17:40 ` Daniel P. Berrangé
2024-02-09 21:22 ` [PATCH 06/23] qemu-img: refresh options/--help for "commit" command Michael Tokarev
2024-02-09 21:22 ` [PATCH 07/23] qemu-img: refresh options/--help for "compare" command Michael Tokarev
2024-02-09 21:22 ` [PATCH 08/23] qemu-img: refresh options/--help for "convert" command Michael Tokarev
2024-02-09 21:22 ` [PATCH 09/23] qemu-img: refresh options/--help for "info" command Michael Tokarev
2024-02-09 21:22 ` [PATCH 10/23] qemu-img: refresh options/--help for "map" command Michael Tokarev
2024-02-09 21:22 ` [PATCH 11/23] qemu-img: allow specifying -f fmt for snapshot subcommand Michael Tokarev
2024-02-09 21:41 ` Michael Tokarev
2024-02-20 17:41 ` Daniel P. Berrangé
2024-02-09 21:22 ` [PATCH 12/23] qemu-img: make -l (list) the default for "snapshot" subcommand Michael Tokarev
2024-02-20 17:45 ` Daniel P. Berrangé
2024-02-20 18:51 ` Michael Tokarev
2024-02-21 12:12 ` Michael Tokarev
2024-02-09 21:22 ` [PATCH 13/23] qemu-img: refresh options/--help for "snapshot" command Michael Tokarev
2024-02-09 21:22 ` [PATCH 14/23] qemu-img: refresh options/--help for "rebase" command Michael Tokarev
2024-02-09 21:22 ` [PATCH 15/23] qemu-img: resize: do not always eat last argument Michael Tokarev
2024-02-20 17:57 ` Daniel P. Berrangé
2024-02-21 12:19 ` Michael Tokarev
2024-02-09 21:22 ` [PATCH 16/23] qemu-img: refresh options/--help for "resize" command Michael Tokarev
2024-02-09 21:22 ` [PATCH 17/23] qemu-img: refresh options/--help for "amend" command Michael Tokarev
2024-02-09 21:22 ` [PATCH 18/23] qemu-img: refresh options/--help for "bench" command Michael Tokarev
2024-02-09 21:22 ` [PATCH 19/23] qemu-img: refresh options/--help for "bitmap" command Michael Tokarev
2024-02-09 21:22 ` [PATCH 20/23] qemu-img: refresh options/--help for "dd" command Michael Tokarev
2024-02-09 21:22 ` [PATCH 21/23] qemu-img: refresh options/--help for "measure" command Michael Tokarev
2024-02-09 21:22 ` [PATCH 22/23] qemu-img: implement short --help, remove global help() function Michael Tokarev
2024-02-20 18:46 ` Daniel P. Berrangé
2024-02-09 21:22 ` [PATCH 23/23] qemu-img: inline list of supported commands, remove qemu-img-cmds.h include Michael Tokarev
2024-02-20 18:48 ` Daniel P. Berrangé
2024-02-20 19:02 ` Michael Tokarev
2024-02-20 19:06 ` Daniel P. Berrangé
2024-02-21 16:31 ` Michael Tokarev
2024-02-21 16:45 ` Daniel P. Berrangé
2024-02-09 22:26 ` [PATCH 00/23] qemu-img: refersh options and --help handling Michael Tokarev
2024-02-20 18:53 ` Daniel P. Berrangé
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=ZdTyUVIV0obAL1kG@redhat.com \
--to=berrange@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 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).