aboutsummaryrefslogtreecommitdiff
path: root/qemu-img.c
diff options
context:
space:
mode:
authorJeff Cody <jcody@redhat.com>2014-04-25 17:02:32 -0400
committerKevin Wolf <kwolf@redhat.com>2014-04-28 17:36:30 +0200
commit7db1689c35a6f7477c691c31232ec10725ba9dfe (patch)
tree804d7e586539064bb4b5952427613bc2650bbd33 /qemu-img.c
parente2da502c003b9a91b4aea7684959192bd07c1f1d (diff)
block: fix qemu-img --help invocation
This fixes a bug introduced in commit ac1307ab, that caused the '--help' option to not be recognized as a valid command, and not print any help. Signed-off-by: Jeff Cody <jcody@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'qemu-img.c')
-rw-r--r--qemu-img.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/qemu-img.c b/qemu-img.c
index 968b4c8e83..d884324c8f 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -2789,6 +2789,12 @@ int main(int argc, char **argv)
{
const img_cmd_t *cmd;
const char *cmdname;
+ int c;
+ int option_index = 0;
+ static const struct option long_options[] = {
+ {"help", no_argument, 0, 'h'},
+ {0, 0, 0, 0}
+ };
#ifdef CONFIG_POSIX
signal(SIGPIPE, SIG_IGN);
@@ -2803,15 +2809,20 @@ int main(int argc, char **argv)
error_exit("Not enough arguments");
}
cmdname = argv[1];
- argc--; argv++;
/* find the command */
for(cmd = img_cmds; cmd->name != NULL; cmd++) {
if (!strcmp(cmdname, cmd->name)) {
- return cmd->handler(argc, argv);
+ return cmd->handler(argc - 1, argv + 1);
}
}
+ c = getopt_long(argc, argv, "h", long_options, &option_index);
+
+ if (c == 'h') {
+ help();
+ }
+
/* not found */
error_exit("Command not found: %s", cmdname);
}