Skip Menu |

This queue is for tickets about the Getopt-Long CPAN distribution.

Report information
The Basics
Id: 75756
Status: rejected
Priority: 0/
Queue: Getopt-Long

People
Owner: Nobody in particular
Requestors: sharyanto [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Allow more characters in option name?
I wonder if Getopt::Long can support non-alphanumeric characters aside from "-". For example: --foo:json --foo:yaml --name.min --name.max It will prevent me from having to fork the module :-) Thanks. Regards, Steven
On Tue Mar 13 19:52:03 2012, SHARYANTO wrote: Show quoted text
> I wonder if Getopt::Long can support non-alphanumeric characters aside > from "-". For example: > > --foo:json > --foo:yaml > --name.min > --name.max
It could but it goes against all existing conventions for command line options. Also, it is easy to introduce ambiguities, e.g. GetOptions( "foo:s" ) Does this mean the option name is "foo:s" or is it option "foo" taking an optional string argument? So I'd suggest to reconsider whether this would be really necessary. Is there a reason "--name-min" and such cannot be used in your case? -- Johan
On Wed Mar 14 03:24:13 2012, JV wrote: Show quoted text
> On Tue Mar 13 19:52:03 2012, SHARYANTO wrote:
> > I wonder if Getopt::Long can support non-alphanumeric characters
aside Show quoted text
> > from "-". For example: > > > > --foo:json > > --foo:yaml > > --name.min > > --name.max
> > It could but it goes against all existing conventions for command line > options. > > Also, it is easy to introduce ambiguities, e.g. > > GetOptions( "foo:s" ) > > Does this mean the option name is "foo:s" or is it option "foo" taking > an optional string argument? > > So I'd suggest to reconsider whether this would be really necessary. > Is there a reason "--name-min" and such cannot be used in your case?
Background: One of my modules translates command-line options to function arguments, e.g. --foo 1 to $foo = 1 and --bar-baz 2 or --bar_baz 2 to $bar_baz = 2. Although only alphanums + underscores are allowed for the argument names, all kinds of names should be possible. I also want to allow YAML (or JSON) decoding so the module can assign data structures to the arguments, e.g. --foo.json='[1,2]'. There is also another module which I'm working on, which translates command-line options to data access query (like SQL). The options are table column names, and I want to allow filters for them, like -- col.min=1 --col.max=10 which will eventually be translated into SQL clause 'col BETWEEN 1 AND 10'. Or even --col.not.yaml='{a: 1}' which can be translated into Perl expression 'Dump($col) ne Dump({a=>1})'. Of course I can also use --foo-json, --col-min, --col-max, --col-not- yaml, but an out-of-band separator character is preferred. As one can imagine an argument or column named being named $foo_json or 'col_min' and there can be confusion on the command-line. As for option specification syntax, we can do something like: GetOptions( "[foo:yaml]:s" ) GetOptions( "[col.min]:i" ) GetOptions( "[another=opt+]=s" ) although I'm not sure you want to go there. I believe some characters like dot (.) and slash (/) currently do not clash with characters used in option specification. Regards, Steven
Thanks for the clarification. I'd consider using hash options for a situation like yours. --option col.min=1 --option col.max=10 With a one-character shortcut and option bundling, this can be shortened to something similar to -Ocol.min=1 -Ocol.max=10 -Oyaml:col-not='{a: 1}' or -Cmin=1 -Cmax=10 -Ycol-not='{a: 1}' short for --col-option min=1 --col-option max=10 --yaml-option col-not='{a: 1}' Looks pretty close to your desired syntax.
On Thu Mar 15 02:56:33 2012, JV wrote: Show quoted text
> Thanks for the clarification. > > I'd consider using hash options for a situation like yours. > > --option col.min=1 --option col.max=10 > > With a one-character shortcut and option bundling, this can be
shortened Show quoted text
> to something similar to > > -Ocol.min=1 -Ocol.max=10 -Oyaml:col-not='{a: 1}' > > or > > -Cmin=1 -Cmax=10 -Ycol-not='{a: 1}' > > short for > > --col-option min=1 --col-option max=10 --yaml-option col-not='{a:
1}' Show quoted text
> > Looks pretty close to your desired syntax.
Thanks for the suggestions. I'll probably settle with using dash for now (--col-min, --col-max, --foo-yaml, --col-min-yaml), although I did test adding a dot support earlier today; I still might package it as Getopt::LongDot or something. These two ways are simpler for my case because I also have code for doing bash completion on option names. Regards, Steven