[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 35/54] qemu-img: Allow -o help with incomplete argume
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 35/54] qemu-img: Allow -o help with incomplete argument list |
Date: |
Fri, 21 Feb 2014 23:12:32 +0100 |
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 <address@hidden>
Reviewed-by: Jeff Cody <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
qemu-img.c | 58 +++++++++++++++++++++++++++++++++++-----------------------
1 file changed, 35 insertions(+), 23 deletions(-)
diff --git a/qemu-img.c b/qemu-img.c
index 6ceaeb2..5512f5b 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;
@@ -394,10 +397,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);
+ }
+
if (optind >= argc) {
help();
}
- filename = argv[optind++];
+ optind++;
/* Get image size, if specified */
if (optind < argc) {
@@ -421,11 +430,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 (local_err) {
@@ -1269,17 +1273,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");
@@ -2689,15 +2694,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) {
@@ -2709,6 +2720,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
- [Qemu-devel] [PULL 26/54] vmdk: push vmdk_read_desc up to caller, (continued)
- [Qemu-devel] [PULL 26/54] vmdk: push vmdk_read_desc up to caller, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 24/54] vvfat: correctly propagate errors, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 27/54] vmdk: do not try opening a file as both image and descriptor, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 28/54] vmdk: correctly propagate errors, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 29/54] block: do not abuse EMEDIUMTYPE, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 30/54] vdi: say why an image is bad, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 31/54] qemu-option: has_help_option() and is_valid_option_list(), Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 32/54] qemu-img create: Support multiple -o options, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 33/54] qemu-img convert: Support multiple -o options, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 34/54] qemu-img amend: Support multiple -o options, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 35/54] qemu-img: Allow -o help with incomplete argument list,
Kevin Wolf <=
- [Qemu-devel] [PULL 36/54] qemu-iotests: Check qemu-img command line parsing, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 37/54] qemu-config: Sections must consist of keys, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 38/54] qdict: Extract non-QDicts in qdict_array_split(), Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 41/54] quorum: Create quorum.c, add QuorumChildRequest and QuorumAIOCB., Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 42/54] quorum: Create BDRVQuorumState and BlkDriver and do init., Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 43/54] quorum: Add quorum_aio_writev and its dependencies., Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 40/54] check-qdict: Test termination of qdict_array_split(), Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 39/54] check-qdict: Adjust test for qdict_array_split(), Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 44/54] blkverify: Extract qemu_iovec_clone() and qemu_iovec_compare() from blkverify., Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 45/54] quorum: Add quorum_aio_readv., Kevin Wolf, 2014/02/21