From: Jeff Cody <jcody@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: mreitz@redhat.com, famz@redhat.com, qemu-devel@nongnu.org,
stefanha@redhat.com, armbru@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2 5/6] qemu-img: Allow -o help with incomplete argument list
Date: Thu, 20 Feb 2014 15:05:15 -0500 [thread overview]
Message-ID: <20140220200515.GG30664@localhost.localdomain> (raw)
In-Reply-To: <1392908243-8835-6-git-send-email-kwolf@redhat.com>
On Thu, Feb 20, 2014 at 03:57:22PM +0100, Kevin Wolf wrote:
> This patch allows using 'qemu-img $subcmd -o help' for the create,
> convert and amend subcommands, without specifying the previously
> required filename arguments.
>
> Note that it's still allowed and meaningful to specify a filename: An
> invocation like 'qemu-img create -o help sheepdog:foo' will also display
> options that are provided by the Sheepdog driver.
>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
> qemu-img.c | 58 +++++++++++++++++++++++++++++++++++-----------------------
> 1 file changed, 35 insertions(+), 23 deletions(-)
>
> diff --git a/qemu-img.c b/qemu-img.c
> index d6dc7ec..98ddbe7 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -250,16 +250,19 @@ static int print_block_option_help(const char *filename, const char *fmt)
> return 1;
> }
>
> - proto_drv = bdrv_find_protocol(filename, true);
> - if (!proto_drv) {
> - error_report("Unknown protocol '%s'", filename);
> - return 1;
> - }
> -
> create_options = append_option_parameters(create_options,
> drv->create_options);
> - create_options = append_option_parameters(create_options,
> - proto_drv->create_options);
> +
> + if (filename) {
> + proto_drv = bdrv_find_protocol(filename, true);
> + if (!proto_drv) {
> + error_report("Unknown protocol '%s'", filename);
> + return 1;
> + }
> + create_options = append_option_parameters(create_options,
> + proto_drv->create_options);
> + }
> +
> print_option_help(create_options);
> free_option_parameters(create_options);
> return 0;
> @@ -390,10 +393,16 @@ static int img_create(int argc, char **argv)
> }
>
> /* Get the filename */
> + filename = (optind < argc) ? argv[optind] : NULL;
> + if (options && has_help_option(options)) {
> + g_free(options);
> + return print_block_option_help(filename, fmt);
> + }
> +
Same comment as patch #2 with regards to common cleanup code in
img_create().
Reviewed-by: Jeff Cody <jcody@redhat.com>
> if (optind >= argc) {
> help();
> }
> - filename = argv[optind++];
> + optind++;
>
> /* Get image size, if specified */
> if (optind < argc) {
> @@ -417,11 +426,6 @@ static int img_create(int argc, char **argv)
> help();
> }
>
> - if (options && has_help_option(options)) {
> - g_free(options);
> - return print_block_option_help(filename, fmt);
> - }
> -
> bdrv_img_create(filename, fmt, base_filename, base_fmt,
> options, img_size, BDRV_O_FLAGS, &local_err, quiet);
> if (error_is_set(&local_err)) {
> @@ -1260,17 +1264,18 @@ static int img_convert(int argc, char **argv)
> }
>
> bs_n = argc - optind - 1;
> - if (bs_n < 1) {
> - help();
> - }
> -
> - out_filename = argv[argc - 1];
> + out_filename = bs_n >= 1 ? argv[argc - 1] : NULL;
>
> if (options && has_help_option(options)) {
> ret = print_block_option_help(out_filename, out_fmt);
> goto out;
> }
>
> + if (bs_n < 1) {
> + help();
> + }
> +
> +
> if (bs_n > 1 && out_baseimg) {
> error_report("-B makes no sense when concatenating multiple input "
> "images");
> @@ -2675,15 +2680,21 @@ static int img_amend(int argc, char **argv)
> }
> }
>
> - if (optind != argc - 1) {
> + if (!options) {
> help();
> }
>
> - if (!options) {
> - help();
> + filename = (optind == argc - 1) ? argv[argc - 1] : NULL;
> + if (fmt && has_help_option(options)) {
> + /* If a format is explicitly specified (and possibly no filename is
> + * given), print option help here */
> + ret = print_block_option_help(filename, fmt);
> + goto out;
> }
>
> - filename = argv[argc - 1];
> + if (optind != argc - 1) {
> + help();
> + }
>
> bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_RDWR, true, quiet);
> if (!bs) {
> @@ -2695,6 +2706,7 @@ static int img_amend(int argc, char **argv)
> fmt = bs->drv->format_name;
>
> if (has_help_option(options)) {
> + /* If the format was auto-detected, print option help here */
> ret = print_block_option_help(filename, fmt);
> goto out;
> }
> --
> 1.8.1.4
>
>
next prev parent reply other threads:[~2014-02-20 20:05 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-20 14:57 [Qemu-devel] [PATCH v2 0/6] qemu-img: Support multiple -o options Kevin Wolf
2014-02-20 14:57 ` [Qemu-devel] [PATCH v2 1/6] qemu-option: Introduce has_help_option() Kevin Wolf
2014-02-20 15:28 ` Eric Blake
2014-02-20 20:21 ` Jeff Cody
2014-02-20 14:57 ` [Qemu-devel] [PATCH v2 2/6] qemu-img create: Support multiple -o options Kevin Wolf
2014-02-20 15:52 ` Eric Blake
2014-02-20 16:24 ` Eric Blake
2014-02-20 19:14 ` Jeff Cody
2014-02-20 14:57 ` [Qemu-devel] [PATCH v2 3/6] qemu-img convert: " Kevin Wolf
2014-02-20 16:01 ` Eric Blake
2014-02-20 19:33 ` Jeff Cody
2014-02-20 19:38 ` Eric Blake
2014-02-20 14:57 ` [Qemu-devel] [PATCH v2 4/6] qemu-img amend: " Kevin Wolf
2014-02-20 16:18 ` Eric Blake
2014-02-20 19:39 ` Jeff Cody
2014-02-20 14:57 ` [Qemu-devel] [PATCH v2 5/6] qemu-img: Allow -o help with incomplete argument list Kevin Wolf
2014-02-20 16:58 ` Eric Blake
2014-02-20 20:05 ` Jeff Cody [this message]
2014-02-20 14:57 ` [Qemu-devel] [PATCH v2 6/6] qemu-iotests: Check qemu-img command line parsing Kevin Wolf
2014-02-20 17:51 ` Eric Blake
2014-02-20 18:42 ` Jeff Cody
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=20140220200515.GG30664@localhost.localdomain \
--to=jcody@redhat.com \
--cc=armbru@redhat.com \
--cc=famz@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.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 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.