diff mbox

block: fix qemu-img --help invocation

Message ID 92ddedd45b3e1f5be4e7485cb9dfdbdb2d3b97ad.1398450303.git.jcody@redhat.com
State New
Headers show

Commit Message

Jeff Cody April 25, 2014, 6:27 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.

This also restores the previous behavior of qemu-img printing the full
help when called with no arguments.

Signed-off-by: Jeff Cody <jcody@redhat.com>
---
 qemu-img.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Eric Blake April 25, 2014, 6:39 p.m. UTC | #1
On 04/25/2014 12:27 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.
> 
> This also restores the previous behavior of qemu-img printing the full
> help when called with no arguments.
> 
> Signed-off-by: Jeff Cody <jcody@redhat.com>
> ---
>  qemu-img.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/qemu-img.c b/qemu-img.c
> index 4dae84a..3f878f6 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -2800,7 +2800,7 @@ int main(int argc, char **argv)
>      qemu_init_main_loop();
>      bdrv_init();
>      if (argc < 2) {
> -        error_exit("Not enough arguments");
> +        help();
>      }

This now gives exit status 0 where it gave status 1 prior to ac1307ab -
is that intentional?

>      cmdname = argv[1];
>      argc--; argv++;
> @@ -2813,5 +2813,6 @@ int main(int argc, char **argv)
>      }
>  
>      /* not found */
> -    error_exit("Command not found: %s", cmdname);
> +    help();
> +    return 0; /* never reached */

Why do we need a never reached comment if help() is marked noreturn?
Also, this now prints FULL help even for 'qemu-img --huh' - shouldn't we
really distinguish the two, by doing full help 0 status for "--help",
and compressed help status 1 otherwise (aka "unrecognized option
'--huh', try "--help" for details")?
Jeff Cody April 25, 2014, 8:02 p.m. UTC | #2
On Fri, Apr 25, 2014 at 12:39:03PM -0600, Eric Blake wrote:
> On 04/25/2014 12:27 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.
> > 
> > This also restores the previous behavior of qemu-img printing the full
> > help when called with no arguments.
> > 
> > Signed-off-by: Jeff Cody <jcody@redhat.com>
> > ---
> >  qemu-img.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> > 
> > diff --git a/qemu-img.c b/qemu-img.c
> > index 4dae84a..3f878f6 100644
> > --- a/qemu-img.c
> > +++ b/qemu-img.c
> > @@ -2800,7 +2800,7 @@ int main(int argc, char **argv)
> >      qemu_init_main_loop();
> >      bdrv_init();
> >      if (argc < 2) {
> > -        error_exit("Not enough arguments");
> > +        help();
> >      }
> 
> This now gives exit status 0 where it gave status 1 prior to ac1307ab -
> is that intentional?

No, that was unintentional.  But on second though, I'll just move it
back to the way that ac1307ab had it, with the "Not enough arguments"
short help.

> 
> >      cmdname = argv[1];
> >      argc--; argv++;
> > @@ -2813,5 +2813,6 @@ int main(int argc, char **argv)
> >      }
> >  
> >      /* not found */
> > -    error_exit("Command not found: %s", cmdname);
> > +    help();
> > +    return 0; /* never reached */
> 
> Why do we need a never reached comment if help() is marked noreturn?

Honestly, I included it because it was in there previously, and my
assumption was that it was there to suppress warnings for some
compiler version.  I don't know if that is a correct assumption or
not... I didn't think it was worth it to verify that it
wouldn't produce a warning on older compilers, and since it doesn't
hurt anything I put it back (but added the comment).

> Also, this now prints FULL help even for 'qemu-img --huh' - shouldn't we
> really distinguish the two, by doing full help 0 status for "--help",
> and compressed help status 1 otherwise (aka "unrecognized option
> '--huh', try "--help" for details")?

The full help status is the same as the previous behavior, prior to
ac1307ab.  I'll fix v2 though so that it parses long opts in main(),
to actually recognize "--help".

Jeff
diff mbox

Patch

diff --git a/qemu-img.c b/qemu-img.c
index 4dae84a..3f878f6 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -2800,7 +2800,7 @@  int main(int argc, char **argv)
     qemu_init_main_loop();
     bdrv_init();
     if (argc < 2) {
-        error_exit("Not enough arguments");
+        help();
     }
     cmdname = argv[1];
     argc--; argv++;
@@ -2813,5 +2813,6 @@  int main(int argc, char **argv)
     }
 
     /* not found */
-    error_exit("Command not found: %s", cmdname);
+    help();
+    return 0; /* never reached */
 }