[libvirt] [PATCH] virsh: don't shorten incorrect arguments

Ján Tomko jtomko at redhat.com
Tue Apr 23 14:08:53 UTC 2013


https://bugzilla.redhat.com/show_bug.cgi?id=949373

Print the whole incorrect argument as specified by the user
instead of the short option.

Before:
$ virsh --debu
error: option '-d' requires an argument
$ virsh ---debu
error: unsupported option '-
$ virsh --debu c
error: option -d takes a numeric argument

After:
$ virsh --debu
error: option '--debu' requires an argument
$ virsh ---debu
error: unsupported option '---debu'. See --help.
$ virsh --debu c
error: option --debu takes a numeric argument
---
 tools/virsh.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 4cd93ca..3856f62 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -2997,7 +2997,7 @@ vshParseArgv(vshControl *ctl, int argc, char **argv)
         switch (arg) {
         case 'd':
             if (virStrToLong_i(optarg, NULL, 10, &debug) < 0) {
-                vshError(ctl, "%s", _("option -d takes a numeric argument"));
+                vshError(ctl, _("option %s takes a numeric argument"), argv[optind - 2]);
                 exit(EXIT_FAILURE);
             }
             if (debug < VSH_ERR_DEBUG || debug > VSH_ERR_ERROR)
@@ -3048,10 +3048,10 @@ vshParseArgv(vshControl *ctl, int argc, char **argv)
             }
             break;
         case ':':
-            vshError(ctl, _("option '-%c' requires an argument"), optopt);
+            vshError(ctl, _("option '%s' requires an argument"), argv[optind - 1]);
             exit(EXIT_FAILURE);
         case '?':
-            vshError(ctl, _("unsupported option '-%c'. See --help."), optopt);
+            vshError(ctl, _("unsupported option '%s'. See --help."), argv[optind - 1]);
             exit(EXIT_FAILURE);
         default:
             vshError(ctl, _("unknown option"));
-- 
1.8.1.5




More information about the libvir-list mailing list