From: "Denis V. Lunev" <den@openvz.org>
To: qemu-devel@nongnu.org, qemu-block@nongnu.org
Cc: eblake@redhat.com, "Denis V. Lunev" <den@openvz.org>,
Paolo Bonzini <pbonzini@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Kevin Wolf <kwolf@redhat.com>
Subject: [Qemu-devel] [PATCH 6/7] qemu-img: move common options parsing before commands processing
Date: Tue, 14 Jun 2016 13:08:18 +0300 [thread overview]
Message-ID: <1465898899-1586-7-git-send-email-den@openvz.org> (raw)
In-Reply-To: <1465898899-1586-1-git-send-email-den@openvz.org>
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 <den@openvz.org>
Reviewed-by: Eric Blake <eblake@redhat.com>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Stefan Hajnoczi <stefanha@redhat.com>
CC: Kevin Wolf <kwolf@redhat.com>
---
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 251386b..b4217e4 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -91,9 +91,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"
@@ -3806,7 +3809,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}
};
@@ -3829,27 +3832,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 cbe50e9..f1b874d 100644
--- a/qemu-img.texi
+++ b/qemu-img.texi
@@ -1,6 +1,6 @@
@example
@c man begin SYNOPSIS
-@command{qemu-img} @var{command} [@var{command} @var{options}]
+@command{qemu-img} [@var{standard} @var{options}] @var{command} [@var{command} @var{options}]
@c man end
@end example
@@ -16,6 +16,14 @@ inconsistent state.
@c man begin OPTIONS
+Standard options:
+@table @option
+@item -h, --help
+Display this help and exit
+@item -V, --version
+Display version information and exit
+@end table
+
The following commands are supported:
@include qemu-img-cmds.texi
--
2.1.4
next prev parent reply other threads:[~2016-06-14 10:08 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-14 10:08 [Qemu-devel] [PATCH v6 0/7] trace: enable tracing in qemu-io/qemu-nbd/qemu-img Denis V. Lunev
2016-06-14 10:08 ` [Qemu-devel] [PATCH 1/7] doc: move text describing --trace to specific .texi file Denis V. Lunev
2016-06-14 21:49 ` Eric Blake
2016-06-14 21:50 ` Eric Blake
2016-06-14 10:08 ` [Qemu-devel] [PATCH 2/7] doc: sync help descriprion for --trace with man for qemu.1 Denis V. Lunev
2016-06-14 21:50 ` Eric Blake
2016-06-14 10:08 ` [Qemu-devel] [PATCH 3/7] trace: move qemu_trace_opts to trace/control.c Denis V. Lunev
2016-06-14 10:08 ` [Qemu-devel] [PATCH 4/7] trace: enable tracing in qemu-io Denis V. Lunev
2016-06-14 10:08 ` [Qemu-devel] [PATCH 5/7] trace: enable tracing in qemu-nbd Denis V. Lunev
2016-06-14 21:51 ` Eric Blake
2016-06-14 10:08 ` Denis V. Lunev [this message]
2016-06-14 10:08 ` [Qemu-devel] [PATCH 7/7] trace: enable tracing in qemu-img Denis V. Lunev
2016-06-14 21:51 ` Eric Blake
-- strict thread matches above, loose matches on Subject: below --
2016-06-17 14:44 [Qemu-devel] [PATCH v9 0/7] trace: enable tracing in qemu-io/qemu-nbd/qemu-img Denis V. Lunev
2016-06-17 14:44 ` [Qemu-devel] [PATCH 6/7] qemu-img: move common options parsing before commands processing Denis V. Lunev
2016-06-17 13:48 [Qemu-devel] [PATCH v8 0/7] trace: enable tracing in qemu-io/qemu-nbd/qemu-img Denis V. Lunev
2016-06-17 13:48 ` [Qemu-devel] [PATCH 6/7] qemu-img: move common options parsing before commands processing Denis V. Lunev
2016-06-16 7:15 [Qemu-devel] [PATCH v7 0/7] trace: enable tracing in qemu-io/qemu-nbd/qemu-img Denis V. Lunev
2016-06-16 7:15 ` [Qemu-devel] [PATCH 6/7] qemu-img: move common options parsing before commands processing Denis V. Lunev
2016-06-17 13:55 ` Stefan Hajnoczi
2016-06-14 9:16 [Qemu-devel] [PATCH v5 0/7] trace: enable tracing in qemu-io/qemu-nbd/qemu-img Denis V. Lunev
2016-06-14 9:16 ` [Qemu-devel] [PATCH 6/7] qemu-img: move common options parsing before commands processing Denis V. Lunev
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=1465898899-1586-7-git-send-email-den@openvz.org \
--to=den@openvz.org \
--cc=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--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 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).