Skip to contentSkip to conversation

qemu-img: show help for invalid global options

PATCH Superseded Stefan Hajnoczi 3 participants 4 messages Mar 13, 2017 – Mar 17, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qemu-img: show help for invalid global options

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.

---
 qemu-img.c | 1 +
 1 file changed, 1 insertion(+)
qemu-img.c +1 -0
index 98b836b..ce293a4 100644
@@ -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':
Signature · 1 line
2.9.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Stefan Hajnoczi

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.

Quoted 7 lines

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

---
 qemu-img.c | 1 +
 1 file changed, 1 insertion(+)
Quoted 14 lines
qemu-img.c +1 -0
index 98b836b..ce293a4 100644
@@ -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':
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw
In reply to Stefan Hajnoczi
Quoted 10 lines · Stefan Hajnoczi

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.

Quoted 7 lines

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

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

#3 lore raw
Quoted 19 lines · Max Reitz
Quoted 10 lines · Stefan Hajnoczi

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.

Quoted 7 lines

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

---
 qemu-img.c | 1 +
 1 file changed, 1 insertion(+)
Quoted 8 lines

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