qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Denis V. Lunev" <den@openvz.org>
To: qemu-block@nongnu.org, qemu-devel@nongnu.org
Cc: den@openvz.org, Eric Blake <eblake@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Kevin Wolf <kwolf@redhat.com>
Subject: [Qemu-devel] [PATCH 4/5] qemu-img: move common options parsing before commands processing
Date: Thu,  2 Jun 2016 21:35:44 +0300	[thread overview]
Message-ID: <1464892545-26544-5-git-send-email-den@openvz.org> (raw)
In-Reply-To: <1464892545-26544-1-git-send-email-den@openvz.org>

This is necessary to enable creation of common qemu-img options which will
be specified before command.

Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: 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 | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index 4b56ad3..aa85b6c 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -3499,26 +3499,33 @@ 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, "+h", 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);
-        return 0;
+    /* reset getopt_long scanning */
+    argc -= optind;
+    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 */
-- 
2.1.4

  parent reply	other threads:[~2016-06-02 18:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-02 18:35 [Qemu-devel] [PATCH v3 0/5] trace: enable tracing in qemu-io/qemu-nbd/qemu-img Denis V. Lunev
2016-06-02 18:35 ` [Qemu-devel] [PATCH 1/5] trace: move qemu_trace_opts to trace/control.c Denis V. Lunev
2016-06-02 18:35 ` [Qemu-devel] [PATCH 2/5] trace: enable tracing in qemu-io Denis V. Lunev
2016-06-02 18:35 ` [Qemu-devel] [PATCH 3/5] trace: enable tracing in qemu-nbd Denis V. Lunev
2016-06-03 14:46   ` Eric Blake
2016-06-03 14:48     ` Denis V. Lunev
2016-06-02 18:35 ` Denis V. Lunev [this message]
2016-06-03 14:50   ` [Qemu-devel] [PATCH 4/5] qemu-img: move common options parsing before commands processing Eric Blake
2016-06-02 18:35 ` [Qemu-devel] [PATCH 5/5] trace: enable tracing in qemu-img Denis V. Lunev
2016-06-03 14:55   ` Eric Blake
2016-06-03 14:58     ` 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=1464892545-26544-5-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).