summaryrefslogtreecommitdiff
path: root/qemu-img.c
diff options
context:
space:
mode:
authorJeff Cody <jcody@redhat.com>2014-04-28 14:37:18 -0400
committerKevin Wolf <kwolf@redhat.com>2014-04-29 10:36:35 +0200
commit5f6979cba9f63480d38e9deb72b565c6781ac0e8 (patch)
tree77517f8fef5b62393fa4897f354c0dfd9b8fe1e0 /qemu-img.c
parentf0e973601250a3f1579ff77230c419c562958fa8 (diff)
downloadqemu-5f6979cba9f63480d38e9deb72b565c6781ac0e8.tar.gz
block: Add '--version' option to qemu-img
This allows qemu-img to print out version information, without needing to print the long help wall of text. While there, perform some minor whitespace cleanup, and remove the unused option_index variable in the call to getopt_long(). Reported-by: Eric Blake <eblake@redhat.com> 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, 11 insertions, 4 deletions
diff --git a/qemu-img.c b/qemu-img.c
index d884324c8f..96f44638b7 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -33,6 +33,9 @@
#include "block/qapi.h"
#include <getopt.h>
+#define QEMU_IMG_VERSION "qemu-img version " QEMU_VERSION \
+ ", Copyright (c) 2004-2008 Fabrice Bellard\n"
+
typedef struct img_cmd_t {
const char *name;
int (*handler)(int argc, char **argv);
@@ -75,7 +78,7 @@ static void QEMU_NORETURN GCC_FMT_ATTR(1, 2) error_exit(const char *fmt, ...)
static void QEMU_NORETURN help(void)
{
const char *help_msg =
- "qemu-img version " QEMU_VERSION ", Copyright (c) 2004-2008 Fabrice Bellard\n"
+ QEMU_IMG_VERSION
"usage: qemu-img command [command options]\n"
"QEMU disk image utility\n"
"\n"
@@ -2790,9 +2793,9 @@ 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'},
+ {"version", no_argument, 0, 'v'},
{0, 0, 0, 0}
};
@@ -2811,17 +2814,21 @@ int main(int argc, char **argv)
cmdname = argv[1];
/* find the command */
- for(cmd = img_cmds; cmd->name != NULL; cmd++) {
+ for (cmd = img_cmds; cmd->name != NULL; cmd++) {
if (!strcmp(cmdname, cmd->name)) {
return cmd->handler(argc - 1, argv + 1);
}
}
- c = getopt_long(argc, argv, "h", long_options, &option_index);
+ c = getopt_long(argc, argv, "h", long_options, NULL);
if (c == 'h') {
help();
}
+ if (c == 'v') {
+ printf(QEMU_IMG_VERSION);
+ return 0;
+ }
/* not found */
error_exit("Command not found: %s", cmdname);