[Qemu-devel] [PATCH] qemu-img: show help for invalid global options

Stefan Hajnoczi posted 1 patch 8 years, 7 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20170313051108.26811-1-stefanha@redhat.com
Test checkpatch passed
Test docker passed
qemu-img.c | 1 +
1 file changed, 1 insertion(+)
[Qemu-devel] [PATCH] qemu-img: show help for invalid global options
Posted by Stefan Hajnoczi 8 years, 7 months ago
The qemu-img sub-command executes regardless of invalid global options:

  $ qemu-img --foo info test.img
  qemu-img: unrecognized option '--foo'
  image: test.img
  ...

The unrecognized option warning may be missed by the user.  This can
hide incorrect command-lines in scripts and confuse users.

This patch prints the help information and terminates instead of
executing the sub-command.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 qemu-img.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/qemu-img.c b/qemu-img.c
index 98b836b..ce293a4 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -4339,6 +4339,7 @@ int main(int argc, char **argv)
     while ((c = getopt_long(argc, argv, "+hVT:", long_options, NULL)) != -1) {
         switch (c) {
         case 'h':
+        case '?':
             help();
             return 0;
         case 'V':
-- 
2.9.3


Re: [Qemu-devel] [PATCH] qemu-img: show help for invalid global options
Posted by Eric Blake 8 years, 7 months ago
On 03/13/2017 12:11 AM, Stefan Hajnoczi wrote:
> The qemu-img sub-command executes regardless of invalid global options:
> 
>   $ qemu-img --foo info test.img
>   qemu-img: unrecognized option '--foo'
>   image: test.img
>   ...
> 
> The unrecognized option warning may be missed by the user.  This can
> hide incorrect command-lines in scripts and confuse users.
> 
> This patch prints the help information and terminates instead of
> executing the sub-command.
> 
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  qemu-img.c | 1 +
>  1 file changed, 1 insertion(+)

Reviewed-by: Eric Blake <eblake@redhat.com>

> 
> diff --git a/qemu-img.c b/qemu-img.c
> index 98b836b..ce293a4 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -4339,6 +4339,7 @@ int main(int argc, char **argv)
>      while ((c = getopt_long(argc, argv, "+hVT:", long_options, NULL)) != -1) {
>          switch (c) {
>          case 'h':
> +        case '?':
>              help();
>              return 0;
>          case 'V':
> 

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Re: [Qemu-devel] [PATCH] qemu-img: show help for invalid global options
Posted by Max Reitz 8 years, 7 months ago
On 13.03.2017 06:11, Stefan Hajnoczi wrote:
> The qemu-img sub-command executes regardless of invalid global options:
> 
>   $ qemu-img --foo info test.img
>   qemu-img: unrecognized option '--foo'
>   image: test.img
>   ...
> 
> The unrecognized option warning may be missed by the user.  This can
> hide incorrect command-lines in scripts and confuse users.
> 
> This patch prints the help information and terminates instead of
> executing the sub-command.
> 
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  qemu-img.c | 1 +
>  1 file changed, 1 insertion(+)

Well, now you get blown away by a wall of text and spotting what went
wrong is actually not quite simple. Maybe we should follow the way of
the coreutils, that is:

qemu-img: unrecognized option '--foo'
Try 'qemu-img --help' for more information.

?

Max

Re: [Qemu-devel] [PATCH] qemu-img: show help for invalid global options
Posted by Stefan Hajnoczi 8 years, 7 months ago
On Thu, Mar 16, 2017 at 03:07:29AM +0100, Max Reitz wrote:
> On 13.03.2017 06:11, Stefan Hajnoczi wrote:
> > The qemu-img sub-command executes regardless of invalid global options:
> > 
> >   $ qemu-img --foo info test.img
> >   qemu-img: unrecognized option '--foo'
> >   image: test.img
> >   ...
> > 
> > The unrecognized option warning may be missed by the user.  This can
> > hide incorrect command-lines in scripts and confuse users.
> > 
> > This patch prints the help information and terminates instead of
> > executing the sub-command.
> > 
> > Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> > ---
> >  qemu-img.c | 1 +
> >  1 file changed, 1 insertion(+)
> 
> Well, now you get blown away by a wall of text and spotting what went
> wrong is actually not quite simple. Maybe we should follow the way of
> the coreutils, that is:
> 
> qemu-img: unrecognized option '--foo'
> Try 'qemu-img --help' for more information.
> 
> ?

Sure, I'll add another patch to improve that.

Stefan