[libvirt] [PATCH 1/2] virsh: make -h always give help

Eric Blake eblake at redhat.com
Mon Apr 30 20:31:08 UTC 2012


https://bugzilla.redhat.com/show_bug.cgi?id=817244 mentions that
unlike most other tools, where --help or --version prevent all
further parsing of all later options, virsh was strange in that
--version stopped parsing but --help tried to plow on to the end.
There was no rationale for this original implementation (since
2005!), so I think we can safely conform to common usage patterns.

* tools/virsh.c (main): Drop useless 'help' variable.
---

I think the intent might have been to someday allow:
  virsh -h foo
to be short for
  virsh help foo
but since that hasn't been implemented in 7 years, I think it
is smarter to be consistent with other tools instead.

 tools/virsh.c |   15 ++-------------
 1 files changed, 2 insertions(+), 13 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index e177684..7159744 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -20179,7 +20179,6 @@ vshAllowedEscapeChar(char c)
 static bool
 vshParseArgv(vshControl *ctl, int argc, char **argv)
 {
-    bool help = false;
     int arg, len;
     struct option opt[] = {
         {"debug", required_argument, NULL, 'd'},
@@ -20206,7 +20205,8 @@ vshParseArgv(vshControl *ctl, int argc, char **argv)
             }
             break;
         case 'h':
-            help = true;
+            vshUsage();
+            exit(EXIT_SUCCESS);
             break;
         case 'q':
             ctl->quiet = true;
@@ -20251,17 +20251,6 @@ vshParseArgv(vshControl *ctl, int argc, char **argv)
         }
     }

-    if (help) {
-        if (optind < argc) {
-            vshError(ctl, _("extra argument '%s'. See --help."), argv[optind]);
-            exit(EXIT_FAILURE);
-        }
-
-        /* list all command */
-        vshUsage();
-        exit(EXIT_SUCCESS);
-    }
-
     if (argc > optind) {
         /* parse command */
         ctl->imode = false;
-- 
1.7.7.6




More information about the libvir-list mailing list