Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

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

Report information
The Basics
Id: 70465
Status: resolved
Priority: 0/
Queue: Getopt-Long-Descriptive

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

Bug Information
Severity: Important
Broken in: 0.090
Fixed in: (no value)



Subject: Allow Hidden Options to Be Used
So far as I can tell, hidden options don't currently work: attempting to use one throws an error as if the option truly didn't exist rather than was just hidden. The attached patch fixes this, with a test. There are already tests that hidden options don't appear in the output; this new test additionally checks that a hidden option can actually be used. The problem was that hidden options were being grep-ed out of the specs for the purpose of forming the leader text for the usage line, and those same hidden-option-less specs were being used as the actual specs. The module patch is bigger than I'd like; similar, but not identical, data is needed in several places and fixing this bug without duplicating code involved turning some neat-looking map-s and grep-s into for loops with push-es inside them. I think it's still quite readable, though obviously you may disagree. Cheers. Smylers
Subject: hidden_works.patch
diff --git a/Changes b/Changes index 459394d..059bb1b 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,7 @@ Revision history for Getopt-Long-Descriptive {{$NEXT}} + hidden options can still be used (Smylers) 0.090 2011-04-21 20:43:07 America/New_York bump prereq on Params::Validate to deal with recent buggy versions diff --git a/lib/Getopt/Long/Descriptive.pm b/lib/Getopt/Long/Descriptive.pm index 2b17749..eaab6a4 100644 --- a/lib/Getopt/Long/Descriptive.pm +++ b/lib/Getopt/Long/Descriptive.pm @@ -266,10 +266,6 @@ my %CONSTRAINT = ( our $MungeOptions = 1; -sub _nohidden { - return grep { ! $_->{constraint}->{hidden} } @_; -} - sub _expand { return map { {( spec => $_->[0] || '', @@ -353,19 +349,27 @@ sub _build_describe_options { # not entirely sure that all of this (until the Usage->new) shouldn't be # moved into Usage -- rjbs, 2009-08-19 - my @specs = - map { $_->{spec} } - grep { $_->{desc} ne 'spacer' } - _nohidden(@opts); + my (@specs, @visible_opts, @short, $long); + for (@opts) { + push @specs, $_->{spec} unless $_->{desc} eq 'spacer'; + + unless ($_->{constraint}->{hidden}) { + push @visible_opts, $_; + + for (split /\|/, __PACKAGE__->_strip_assignment($_->{spec})) { + if (length == 1) { + push @short, $_; + } + else { + $long ||= 1; + } + } + } + } my $short = join q{}, sort { lc $a cmp lc $b or $a cmp $b } - grep { /^.$/ } - map { split /\|/ } - map { __PACKAGE__->_strip_assignment($_) } - @specs; - - my $long = grep /\b[^|]{2,}/, @specs; + @short; my %replace = ( "%" => "%", @@ -380,14 +384,14 @@ sub _build_describe_options { $str =~ s/\s{2,}/ /g; my $usage = $class->usage_class->new({ - options => [ _nohidden(@opts) ], + options => \@visible_opts, leader_text => $str, }); Getopt::Long::Configure(@go_conf); my %return; - $usage->die unless GetOptions(\%return, grep { length } @specs); + $usage->die unless GetOptions(\%return, @specs); my @given_keys = keys %return; for my $opt (keys %return) { diff --git a/t/descriptive.t b/t/descriptive.t index 8801473..6f58000 100644 --- a/t/descriptive.t +++ b/t/descriptive.t @@ -2,7 +2,7 @@ use strict; use warnings; -use Test::More tests => 40; +use Test::More tests => 42; use_ok("Getopt::Long::Descriptive"); @@ -86,6 +86,13 @@ is_hidden( qr/a bar option/, ); +is_opt( + [ '--nora' ], + [ [ "nora", "Invisible Nora", { hidden => 1 } ] ], + { nora => 1 }, + "", +); + ### tests for one_of my $foobar = [
I'm sorry I missed this. It no longer applies. Would you consider updating it? I will apply it, really. If possible, submit as pull request to rjbs/Getopt-Long-Descriptive. Otherwise, a patch here is fine. Thanks! -- rjbs
From: smylers [...] cpan.org
On Thu Sep 05 09:25:35 2013, RJBS wrote: Show quoted text
> I'm sorry I missed this. > > It no longer applies.
It turns out that's because Roman Hubacek already dealt with it: https://github.com/rjbs/Getopt-Long-Descriptive/commit/6ffbd47f He went for the implementation change which was less intrusive (but involves repeating iterating over the options), but the example used in the test case is mine, so I'm presuming he took it from this RT ticket. So, no work required, and this ticket can be closed. Smylers
That explains why I was surprised to read a bug report. Oy! Thanks. -- rjbs