qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
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 06/28] qemu-img: create: refresh options/--help
Date: Mon, 26 Feb 2024 14:34:12 +0000	[thread overview]
Message-ID: <ZdyhZAve4WtPnmkc@redhat.com> (raw)
In-Reply-To: <20240221211622.2335170-6-mjt@tls.msk.ru>

On Thu, Feb 22, 2024 at 12:15:47AM +0300, Michael Tokarev wrote:
> 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 | 68 +++++++++++++++++++++++++++++++++++++++++++++++-------
>  1 file changed, 60 insertions(+), 8 deletions(-)
> 
> diff --git a/qemu-img.c b/qemu-img.c
> index 38ac0f1845..7e4c993b9c 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -132,6 +132,31 @@ 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,
> + * 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"
> +"  %s %s %s"

For the global help there's an extra '\n' after 'Usage'. It would be
good go be consistent in this between global and per-command help.

$ ./build/qemu-img --help
qemu-img version 8.2.50 (v8.2.0-1677-g81b20f4b55)
Copyright (c) 2003-2023 Fabrice Bellard and the QEMU Project developers
QEMU disk image utility.  Usage:

  qemu-img [standard options] COMMAND [--help | command options]
...snip...

vs

$ ./build/qemu-img info --help
Display information about image.  Usage:
  qemu-img info [-f FMT | --image-opts] [-b] [-U] [--object OBJDEF]
        [--output human|json] FILENAME
...snip...


I wonder if we should repeat '[standard options]' for the
per-command help too ?


> +"\n"
> +"Arguments:\n"

In the global help you called it 'Standard options', so for
consistency lets use 'Options:' here too.

> +"  -h, --help\n"
> +"     print this help and exit\n"
> +"%s\n",
> +           "qemu-img", ccmd->name,
> +           syntax, arguments);
> +    exit(EXIT_SUCCESS);
> +}
> +
>  /* Please keep in synch with docs/tools/qemu-img.rst */
>  static G_NORETURN
>  void help(void)
> @@ -530,23 +555,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);
>          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,
> +"[-f FMT] [-o FMT_OPTS] [-b BACKING_FILENAME [-F BACKING_FMT]]\n"
> +"        [--object OBJDEF] [-u] FILENAME [SIZE[bkKMGTPE]]\n"
> +,
> +"  -q, --quiet\n"
> +"     quiet operations\n"
> +"  -f, --format FMT\n"
> +"     specifies format of the new image, default is raw\n"
> +"  -o, --options FMT_OPTS\n"
> +"     format-specific options ('-o list' for list)\n"
> +"  -b, --backing BACKING_FILENAME\n"
> +"     stack new image on top of BACKING_FILENAME\n"
> +"     (for formats which support stacking)\n"
> +"  -F, --backing-format BACKING_FMT\n"
> +"     specify format of BACKING_FILENAME\n"
> +"  -u, --backing-unsafe\n"
> +"     do not fail if BACKING_FMT can not be read\n"
> +"  --object OBJDEF\n"
> +"     QEMU user-creatable object (eg encryption key)\n"
> +"  FILENAME\n"
> +"     image file to create.  It will be overridden if exists\n"
> +"  SIZE\n"
> +"     image size with optional suffix (multiplies in 1024)\n"
> +"     SIZE is required unless BACKING_IMG is specified,\n"
> +"     in which case it will be the same as size of BACKING_IMG\n"
> +);
>              break;
>          case 'F':
>              base_fmt = optarg;
> @@ -571,6 +621,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]);
>          }
>      }
>  
> -- 
> 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 :|



  reply	other threads:[~2024-02-26 14:34 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-21 21:15 [PATCH v2 00/28] qemu-img: refersh options and --help handling, cleanups Michael Tokarev
2024-02-21 21:15 ` [PATCH 01/28] qemu-img: stop printing error twice in a few places Michael Tokarev
2024-02-26 14:14   ` Daniel P. Berrangé
2024-02-26 18:58     ` Michael Tokarev
2024-02-26 16:37   ` Michael Tokarev
2024-02-21 21:15 ` [PATCH 02/28] qemu-img: measure: convert img_size to signed, simplify handling Michael Tokarev
2024-02-26 14:19   ` Daniel P. Berrangé
2024-02-21 21:15 ` [PATCH 03/28] qemu-img: create: " Michael Tokarev
2024-02-26 14:19   ` Daniel P. Berrangé
2024-02-21 21:15 ` [PATCH 04/28] qemu-img: global option processing and error printing Michael Tokarev
2024-02-26 14:23   ` Daniel P. Berrangé
2024-02-26 15:40   ` Daniel P. Berrangé
2024-02-21 21:13     ` [PATCH v2.1 " Michael Tokarev
2024-02-26 15:43     ` [PATCH " Michael Tokarev
2024-02-26 16:25       ` Michael Tokarev
2024-02-21 21:15 ` [PATCH 05/28] qemu-img: pass current cmd info into command handlers Michael Tokarev
2024-02-26 14:24   ` Daniel P. Berrangé
2024-02-21 21:15 ` [PATCH 06/28] qemu-img: create: refresh options/--help Michael Tokarev
2024-02-26 14:34   ` Daniel P. Berrangé [this message]
2024-02-26 14:37     ` Michael Tokarev
2024-02-21 21:15 ` [PATCH 07/28] qemu-img: factor out parse_output_format() and use it in the code Michael Tokarev
2024-02-21 21:15 ` [PATCH 08/28] qemu-img: check: refresh options/--help Michael Tokarev
2024-02-21 21:15 ` [PATCH 09/28] qemu-img: simplify --repair error message Michael Tokarev
2024-02-21 21:15 ` [PATCH 10/28] qemu-img: commit: refresh options/--help Michael Tokarev
2024-02-21 21:15 ` [PATCH 11/28] qemu-img: compare: " Michael Tokarev
2024-02-21 21:15 ` [PATCH 12/28] qemu-img: convert: " Michael Tokarev
2024-02-21 21:15 ` [PATCH 13/28] qemu-img: info: " Michael Tokarev
2024-02-21 21:15 ` [PATCH 14/28] qemu-img: map: " Michael Tokarev
2024-02-21 21:15 ` [PATCH 15/28] qemu-img: snapshot: allow specifying -f fmt Michael Tokarev
2024-02-21 21:15 ` [PATCH 16/28] qemu-img: snapshot: make -l (list) the default, simplify option handling Michael Tokarev
2024-02-26 14:36   ` Daniel P. Berrangé
2024-02-21 21:15 ` [PATCH 17/28] qemu-img: snapshot: refresh options/--help Michael Tokarev
2024-02-21 21:15 ` [PATCH 18/28] qemu-img: rebase: " Michael Tokarev
2024-02-21 21:16 ` [PATCH 19/28] qemu-img: resize: do not always eat last argument Michael Tokarev
2024-02-26 14:52   ` Daniel P. Berrangé
2024-02-26 14:59     ` Michael Tokarev
2024-02-21 21:16 ` [PATCH 20/28] qemu-img: resize: refresh options/--help Michael Tokarev
2024-02-21 21:16 ` [PATCH 21/28] qemu-img: amend: " Michael Tokarev
2024-02-21 21:16 ` [PATCH 22/28] qemu-img: bench: " Michael Tokarev
2024-02-21 21:16 ` [PATCH 23/28] qemu-img: bitmap: " Michael Tokarev
2024-02-21 21:16 ` [PATCH 24/28] qemu-img: dd: " Michael Tokarev
2024-02-21 21:16 ` [PATCH 25/28] qemu-img: measure: " Michael Tokarev
2024-02-21 21:16 ` [PATCH 26/28] qemu-img: implement short --help, remove global help() function Michael Tokarev
2024-02-26 14:53   ` Daniel P. Berrangé
2024-02-21 21:16 ` [PATCH 27/28] qemu-img: inline list of supported commands, remove qemu-img-cmds.h include Michael Tokarev
2024-02-26 14:54   ` Daniel P. Berrangé
2024-02-21 21:16 ` [PATCH 28/28] qemu-img: extend cvtnum() and use it in more places Michael Tokarev
2024-02-26 14:57   ` Daniel P. Berrangé
2024-02-26 19:16   ` 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=ZdyhZAve4WtPnmkc@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).