From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35973) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8XTN-0002xQ-Ct for qemu-devel@nongnu.org; Thu, 02 Jun 2016 14:36:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8XTM-0006fb-EL for qemu-devel@nongnu.org; Thu, 02 Jun 2016 14:36:01 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:23651 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8XTL-0006fP-VD for qemu-devel@nongnu.org; Thu, 02 Jun 2016 14:36:00 -0400 From: "Denis V. Lunev" Date: Thu, 2 Jun 2016 21:35:44 +0300 Message-Id: <1464892545-26544-5-git-send-email-den@openvz.org> In-Reply-To: <1464892545-26544-1-git-send-email-den@openvz.org> References: <1464892545-26544-1-git-send-email-den@openvz.org> Subject: [Qemu-devel] [PATCH 4/5] qemu-img: move common options parsing before commands processing List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org, qemu-devel@nongnu.org Cc: den@openvz.org, Eric Blake , Paolo Bonzini , Stefan Hajnoczi , Kevin Wolf This is necessary to enable creation of common qemu-img options which will be specified before command. Signed-off-by: Denis V. Lunev CC: Eric Blake CC: Paolo Bonzini CC: Stefan Hajnoczi CC: Kevin Wolf --- 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