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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 04/23/2013 06:05 PM, Eric Blake wrote:
> On 04/23/2013 08:08 AM, Ján Tomko wrote:
>> https://bugzilla.redhat.com/show_bug.cgi?id=949373
>>
>> Print the whole incorrect argument as specified by the user
>> instead of the short option.
>>
> 
>>          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]);
> 
> I'm not sure this gives the nicest output.  With short option bundling,
> this results in
> 
> $ tools/virsh -rd
> error: option '-rd' requires an argument
> 
> even though the -r option was just fine, and it is really just the
> bundled '-d' option that has a problem.

The output is even worse with two unrecognized options:
$ tools/virsh -pm
error: unsupported option '.../tools/.libs/virsh'. See --help.

> 
> Also, I wonder if we should be using a non-NULL 5th parameter to
> getopt_long; if you provide a longindex parameter, then you can provide
> a nicer error message that mentions the full "--debug" name (rather than
> the user-typed abbreviation '--debu') by indexing back into the
> long-option table (of course, do this only when it was a long option
> that was misused).

It seems longindex is only set when the option parsing is successful.

If we removed the ':' from optstring and let getopt handle the errors,
it would correctly translate --deb to --debug, but keep the short
options unchanged:

$ tools/virsh --deb
.../virsh: option '--debug' requires an argument
...

$ tools/virsh -rd
.../virsh: option requires an argument -- 'd'
...

Maybe we should revert commit dd71fa1 ([1]) and change the message
to something more generic, for example:
error: See virsh --help.

Jan

[1] http://libvirt.org/git/?p=libvirt.git;a=commitdiff;h=dd71fa1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]