diff mbox

[v2] block: fix qemu-img --help invocation

Message ID 0075648547ab887dae6f6b1a1845d032aec6ed9a.1398459439.git.jcody@redhat.com
State New
Headers show

Commit Message

Jeff Cody April 25, 2014, 9:02 p.m. UTC
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>
---
 qemu-img.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

Comments

Eric Blake April 25, 2014, 9:16 p.m. UTC | #1
On 04/25/2014 03:02 PM, Jeff Cody wrote:
> 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>
> ---
>  qemu-img.c | 15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/qemu-img.c b/qemu-img.c
> index 4dae84a..af47804 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}
> +    };

The addition of --help support makes the absence of --version support
rather obvious.  As a separate patch, it would be nice to add 'qemu-img
--version' to give just version info instead of also spewing usage that
scrolls the version off-screen.

>  
>  #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++) {

Worth fixing the whitespace while in the area?

>          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);

option_index is unused, you could pass NULL here for the same result.

Strict improvement and fixes a regression, so I can live with:
Reviewed-by: Eric Blake <eblake@redhat.com>
Kevin Wolf April 28, 2014, 12:08 p.m. UTC | #2
Am 25.04.2014 um 23:02 hat Jeff Cody geschrieben:
> 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>

Thanks, applied to the block branch.

Kevin
diff mbox

Patch

diff --git a/qemu-img.c b/qemu-img.c
index 4dae84a..af47804 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);
 }