[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 5/6] qemu-img: move common options parsing before co
From: |
Denis V. Lunev |
Subject: |
[Qemu-devel] [PATCH 5/6] qemu-img: move common options parsing before commands processing |
Date: |
Mon, 13 Jun 2016 19:58:24 +0300 |
This is necessary to enable creation of common qemu-img options which will
be specified before command.
The patch also enables '-V' alias to '--version' (exactly like in other
block utilities) and documents this change.
Signed-off-by: Denis V. Lunev <address@hidden>
CC: Eric Blake <address@hidden>
CC: Paolo Bonzini <address@hidden>
CC: Stefan Hajnoczi <address@hidden>
CC: Kevin Wolf <address@hidden>
---
qemu-img.c | 39 ++++++++++++++++++++++++++-------------
qemu-img.texi | 10 +++++++++-
2 files changed, 35 insertions(+), 14 deletions(-)
diff --git a/qemu-img.c b/qemu-img.c
index 4b56ad3..d22ebdf 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -87,9 +87,12 @@ static void QEMU_NORETURN help(void)
{
const char *help_msg =
QEMU_IMG_VERSION
- "usage: qemu-img command [command options]\n"
+ "usage: qemu-img [standard options] command [command options]\n"
"QEMU disk image utility\n"
"\n"
+ " '-h', '--help' display this help and exit\n"
+ " '-V', '--version' output version information and exit\n"
+ "\n"
"Command syntax:\n"
#define DEF(option, callback, arg_string) \
" " arg_string "\n"
@@ -3476,7 +3479,7 @@ int main(int argc, char **argv)
int c;
static const struct option long_options[] = {
{"help", no_argument, 0, 'h'},
- {"version", no_argument, 0, 'v'},
+ {"version", no_argument, 0, 'V'},
{0, 0, 0, 0}
};
@@ -3499,27 +3502,37 @@ int main(int argc, char **argv)
if (argc < 2) {
error_exit("Not enough arguments");
}
- cmdname = argv[1];
qemu_add_opts(&qemu_object_opts);
qemu_add_opts(&qemu_source_opts);
- /* find the command */
- for (cmd = img_cmds; cmd->name != NULL; cmd++) {
- if (!strcmp(cmdname, cmd->name)) {
- return cmd->handler(argc - 1, argv + 1);
+ while ((c = getopt_long(argc, argv, "+hV", long_options, NULL)) != -1) {
+ switch (c) {
+ case 'h':
+ help();
+ return 0;
+ case 'V':
+ printf(QEMU_IMG_VERSION);
+ return 0;
}
}
- c = getopt_long(argc, argv, "h", long_options, NULL);
+ cmdname = argv[optind];
- if (c == 'h') {
- help();
- }
- if (c == 'v') {
- printf(QEMU_IMG_VERSION);
+ /* reset getopt_long scanning */
+ argc -= optind;
+ if (argc < 1) {
return 0;
}
+ argv += optind;
+ optind = 1;
+
+ /* find the command */
+ for (cmd = img_cmds; cmd->name != NULL; cmd++) {
+ if (!strcmp(cmdname, cmd->name)) {
+ return cmd->handler(argc, argv);
+ }
+ }
/* not found */
error_exit("Command not found: %s", cmdname);
diff --git a/qemu-img.texi b/qemu-img.texi
index afaebdd..5a47810 100644
--- a/qemu-img.texi
+++ b/qemu-img.texi
@@ -1,6 +1,6 @@
@example
@c man begin SYNOPSIS
address@hidden @var{command} address@hidden @var{options}]
address@hidden address@hidden @var{options}] @var{command} address@hidden
@var{options}]
@c man end
@end example
@@ -16,6 +16,14 @@ inconsistent state.
@c man begin OPTIONS
+Standard options:
address@hidden @option
address@hidden -h, --help
+Display this help and exit
address@hidden -V, --version
+Display version information and exit
address@hidden table
+
The following commands are supported:
@include qemu-img-cmds.texi
--
2.5.0
- [Qemu-devel] [PATCH v4 0/6] trace: enable tracing in qemu-io/qemu-nbd/qemu-img, Denis V. Lunev, 2016/06/13
- [Qemu-devel] [PATCH 3/6] trace: enable tracing in qemu-io, Denis V. Lunev, 2016/06/13
- [Qemu-devel] [PATCH 2/6] trace: move qemu_trace_opts to trace/control.c, Denis V. Lunev, 2016/06/13
- [Qemu-devel] [PATCH 4/6] trace: enable tracing in qemu-nbd, Denis V. Lunev, 2016/06/13
- [Qemu-devel] [PATCH 1/6] doc: move text describing --trace to specific .texi file, Denis V. Lunev, 2016/06/13
- [Qemu-devel] [PATCH 5/6] qemu-img: move common options parsing before commands processing,
Denis V. Lunev <=
- [Qemu-devel] [PATCH 6/6] trace: enable tracing in qemu-img, Denis V. Lunev, 2016/06/13