Re: [PATCH v2] virsh: fix incorrect argument errors for long options

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

 



On 04/29/2013 11:27 AM, Ján Tomko wrote:
> For long options, print:
> * the option as specified by the user if it's unknown
> * the cannoncial long option if its argument is  not

s/cannonical/canonical/

>   a number (and should be)
> 
> And for missing arguments, print both the short and
> the long option name.
> (Doing only one of those would require either parsing
> argv ourselves or let getopt print the errors, since
> we can't tell long and short options apart by optopt
> or longindex)
> 
> https://bugzilla.redhat.com/show_bug.cgi?id=949373

Listing some before-and-after in the commit message would be very
helpful.  Here's what I tried:

Unknown option:
Before:
$ virsh -x
error: unsupported option '-x'. See --help.
$ virsh --x
error: unsupported option '-
$ virsh -rx
error: unsupported option '-x'. See --help.

After:
$ tools/virsh -x
error: unsupported option '-x'. See --help.
$ tools/virsh --x
error: unsupported option '--x'. See --help.
$ tools/virsh -rx
error: unsupported option '-x'. See --help.

No worse behavior, and definite improvement on the unknown long option.


Incorrect argument:
Before:
$ virsh --d=a
error: option -d takes a numeric argument
$ virsh --deb=a
error: option -d takes a numeric argument

After:
$ tools/virsh -da
error: option -d takes a numeric argument
$ tools/virsh --deb=a
error: option --debug takes a numeric argument

Much nicer on the long option :)


Missing argument:
Before:
$ virsh -d
error: option '-d' requires an argument
$ virsh --deb
error: option '-d' requires an argument

After:
$ tools/virsh -d
error: option '-d'/'--debug' requires an argument
$ tools/virsh --deb
error: option '-d'/'--debug' requires an argument

A bit more verbose, but now it is obvious when a long option was typed,
rather than making you figure out what short option matches your long
option.  And I agree that improving it would require reimplementing too
much of getopt_long, so I can live with it.

ACK.  Reasonable for 1.0.5

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

Attachment: signature.asc
Description: OpenPGP digital signature

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