qemu-img: commit: refresh options/--help

Add missing long options and --help output,
reorder options for consistency.

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Message-ID: <20250531171609.197078-10-mjt@tls.msk.ru>
[kwolf: Fixed up qemu-iotests]
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
Michael Tokarev
2025-05-31 20:15:51 +03:00
committed by Kevin Wolf
parent bf1e1cd357
commit a79d282fc9
3 changed files with 56 additions and 28 deletions

View File

@@ -1047,57 +1047,85 @@ static int img_commit(const img_cmd_t *ccmd, int argc, char **argv)
for(;;) {
static const struct option long_options[] = {
{"help", no_argument, 0, 'h'},
{"object", required_argument, 0, OPTION_OBJECT},
{"format", required_argument, 0, 'f'},
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
{"cache", required_argument, 0, 't'},
{"drop", no_argument, 0, 'd'},
{"base", required_argument, 0, 'b'},
{"rate-limit", required_argument, 0, 'r'},
{"progress", no_argument, 0, 'p'},
{"quiet", no_argument, 0, 'q'},
{"object", required_argument, 0, OPTION_OBJECT},
{0, 0, 0, 0}
};
c = getopt_long(argc, argv, ":f:ht:b:dpqr:",
c = getopt_long(argc, argv, "hf:t:db:r:pq",
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 | --image-opts] [-t CACHE_MODE] [-b BASE_IMG]\n"
" [-d] [-r RATE] [-q] [--object OBJDEF] FILE\n"
,
" -f, --format FMT\n"
" specify FILE image format explicitly (default: probing is used)\n"
" --image-opts\n"
" treat FILE as an option string (key=value,..), not a file name\n"
" (incompatible with -f|--format)\n"
" -t, --cache CACHE_MODE image cache mode (default: " BDRV_DEFAULT_CACHE ")\n"
" -d, --drop\n"
" skip emptying FILE on completion\n"
" -b, --base BASE_IMG\n"
" image in the backing chain to commit change to\n"
" (default: immediate backing file; implies --drop)\n"
" -r, --rate-limit RATE\n"
" I/O rate limit, in bytes per second\n"
" -p, --progress\n"
" display progress information\n"
" -q, --quiet\n"
" quiet mode (produce only error messages if any)\n"
" --object OBJDEF\n"
" defines QEMU user-creatable object\n"
" FILE\n"
" name of the image file, or an option string (key=value,..)\n"
" with --image-opts, to operate on\n"
);
break;
case 'f':
fmt = optarg;
break;
case OPTION_IMAGE_OPTS:
image_opts = true;
break;
case 't':
cache = optarg;
break;
case 'd':
drop = true;
break;
case 'b':
base = optarg;
/* -b implies -d */
drop = true;
break;
case 'd':
drop = true;
break;
case 'p':
progress = true;
break;
case 'q':
quiet = true;
break;
case 'r':
rate_limit = cvtnum("rate limit", optarg);
if (rate_limit < 0) {
return 1;
}
break;
case 'p':
progress = true;
break;
case 'q':
quiet = true;
break;
case OPTION_OBJECT:
user_creatable_process_cmdline(optarg);
break;
case OPTION_IMAGE_OPTS:
image_opts = true;
break;
default:
tryhelp(argv[0]);
}
}

View File

@@ -63,7 +63,7 @@ _supported_proto file
_run_cmd()
{
echo
(echo "$@"; "$@" 2>&1 1>/dev/null) | _filter_testdir
(echo "$@"; "$@" 2>&1 1>/dev/null) | _filter_testdir | _filter_qemu_img
}
_do_run_qemu()

View File

@@ -124,8 +124,8 @@ qemu-img: unrecognized option '-U'
Try 'qemu-img --help' for more information
_qemu_img_wrapper commit -U TEST_DIR/t.qcow2
qemu-img: unrecognized option '-U'
Try 'qemu-img --help' for more information
qemu-img commit: invalid option -- 'U'
Try 'qemu-img commit --help' for more information
_qemu_img_wrapper resize -U TEST_DIR/t.qcow2 32M
qemu-img: unrecognized option '-U'
@@ -248,8 +248,8 @@ qemu-img: unrecognized option '-U'
Try 'qemu-img --help' for more information
_qemu_img_wrapper commit -U TEST_DIR/t.qcow2
qemu-img: unrecognized option '-U'
Try 'qemu-img --help' for more information
qemu-img commit: invalid option -- 'U'
Try 'qemu-img commit --help' for more information
_qemu_img_wrapper resize -U TEST_DIR/t.qcow2 32M
qemu-img: unrecognized option '-U'
@@ -353,8 +353,8 @@ qemu-img: unrecognized option '-U'
Try 'qemu-img --help' for more information
_qemu_img_wrapper commit -U TEST_DIR/t.qcow2
qemu-img: unrecognized option '-U'
Try 'qemu-img --help' for more information
qemu-img commit: invalid option -- 'U'
Try 'qemu-img commit --help' for more information
_qemu_img_wrapper resize -U TEST_DIR/t.qcow2 32M
qemu-img: unrecognized option '-U'