polettix/App-Easer

inconsistent behavior if option name and getopt attributes resolve to different name for option

djerius opened this issue · 3 comments

If both name and getopt are specified in an options specification, and do not resolve to the same name, they result in both names being used in the options hash, e.g.

{
   name     => 'log_level',
   getopt   => 'log-level=s',
   help     => 'log level',
   default  => 'warn',
}

results in $app->config_hash having entries for both log_level (with the default value) and log-level (with that obtained from Getopt::Long::GetOptions).

My assumption was that specifying name would result in that string being used to identify the option in config_hash, e.g. by submitting something like this to Getopt::Long::GetOptions:

my %options;
GetOptions( "log-level=s", \$options{"log_level"}, );
delete @options{ grep ! defined $options{$_}, keys %options };

The name was initially included to avoid thinking about extracting it from getopt. I eventually did that and never used name.

I'd be inclined to remove name completely, but if there's a compelling reason for keeping it I can think about something.

Looking at it, it's just a plain bug. Fixed in 0686ed1.