On Mon, Jul 18, 2016 at 05:40:11PM +0200, Pino Toscano wrote:
On Monday, 18 July 2016 14:43:03 CEST Richard W.M. Jones wrote:
- let validate_key key = - if String.length key == 0 || key == "-" || key == "--" - || key.[0] != '-' then - invalid_arg (sprintf "invalid option key: '%s'" key) + let validate_key = function + | L"" -> invalid_arg "Getopt spec: invalid empty long option" + | L"help" -> invalid_arg "Getopt spec: should not have L\"help\""
Theoretically both Arg and the current Getopt allow applications to provide an own handler for --help, instead of the built-in one.
Sure, but I don't think that's a good idea :-)
Well, I could have avoided that when proposing the final Getopt patch...
Also, there should be the same checks for M"something" of the L"something" ones.
How about I add this case: let validate_key = function + | M s when String.length s <> 2 || (s.[0] <> 'i' && s.[0] <> 'o') -> + invalid_arg "Getopt spec: invalid use of M\"...\" option - only use this for virt-v2v -iX and -oX options" | L"" -> invalid_arg "Getopt spec: invalid empty long option" It effectively excludes any use of the M option except for the special cases in virt-v2v.
IMHO it'd be better to sort the specs at this point, like done before; otherwise, --help (and potentially any non-hidden built-in option added here) will be shown only at the end of the other specs.
At the beginning of the list, and it was deliberate. However it's just a matter of preference, and the options could be sorted later.
Well I'd prefer it sorted, since it won't create arbitrary lines of --help with different order, which look a bit odd.
OK, I changed the sort so it happens after the --help and other options have been added.
Also, making everything ordered was basically the reason for the helper type t, and the mutable state of its specs field.
Indeed - I couldn't work out how to rewrite the code without mutability. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org