[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 03/31] block: Add '--version' option to qemu-img
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 03/31] block: Add '--version' option to qemu-img |
Date: |
Wed, 30 Apr 2014 20:23:35 +0200 |
From: Jeff Cody <address@hidden>
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 <address@hidden>
Signed-off-by: Jeff Cody <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
qemu-img.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/qemu-img.c b/qemu-img.c
index d884324..96f4463 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);
--
1.8.3.1
- [Qemu-devel] [PULL 00/31] Block patches, Kevin Wolf, 2014/04/30
- [Qemu-devel] [PULL 01/31] block: fix qemu-img --help invocation, Kevin Wolf, 2014/04/30
- [Qemu-devel] [PULL 02/31] mirror: Use DIV_ROUND_UP, Kevin Wolf, 2014/04/30
- [Qemu-devel] [PULL 03/31] block: Add '--version' option to qemu-img,
Kevin Wolf <=
- [Qemu-devel] [PULL 04/31] block: Ignore duplicate or NULL format_name in bdrv_iterate_format, Kevin Wolf, 2014/04/30
- [Qemu-devel] [PULL 07/31] block: qemu-iotests - fix image cleanup when using spaced pathnames, Kevin Wolf, 2014/04/30
- [Qemu-devel] [PULL 06/31] mirror: Check for bdrv_get_info result, Kevin Wolf, 2014/04/30
- [Qemu-devel] [PULL 08/31] block: qemu-iotests: make test 019 and 086 work with spaced pathnames, Kevin Wolf, 2014/04/30
- [Qemu-devel] [PULL 05/31] mirror: Fix resource leak when bdrv_getlength fails, Kevin Wolf, 2014/04/30
- [Qemu-devel] [PULL 10/31] iotests: Discarding compressed clusters on qcow2, Kevin Wolf, 2014/04/30
- [Qemu-devel] [PULL 09/31] qcow2: Fix discard, Kevin Wolf, 2014/04/30
- [Qemu-devel] [PULL 11/31] block: Create bdrv_inherited_flags(), Kevin Wolf, 2014/04/30
- [Qemu-devel] [PULL 12/31] block: Create bdrv_backing_flags(), Kevin Wolf, 2014/04/30
- [Qemu-devel] [PULL 13/31] block: Remove BDRV_O_COPY_ON_READ for bs->file, Kevin Wolf, 2014/04/30