diff --git a/lib/Getopt/Lucid.pm b/lib/Getopt/Lucid.pm index 1904f7d..90b58ef 100644 --- a/lib/Getopt/Lucid.pm +++ b/lib/Getopt/Lucid.pm @@ -385,7 +385,7 @@ sub usage { for my $opt ( sort { $a->{strip} cmp $b->{strip} } values %{$self->{spec}} ) { my $names = [ @{ $opt->{names} } ]; push @doc, [ - _build_usage_left_column( $names, \@short_opts ), + _build_usage_left_column( $names, \@short_opts, $opt->{type} ), _build_usage_right_column( $opt->{doc}, $opt->{default}, $opt->{type} ), ]; } @@ -400,7 +400,7 @@ sub usage { } sub _build_usage_left_column { - my ($names, $all_short_opts) = @_; + my ($names, $all_short_opts, $type) = @_; my @sorted_names = sort { length $a <=> length $b } map { my $s = $_; $s =~ s/^-*//; $s } @$names; @@ -409,13 +409,20 @@ sub _build_usage_left_column { push @$all_short_opts, @short_opts; + my $value = + $type eq 'keypair' ? ' key=' + : $type eq 'counter' ? ' []' + : $type ne 'switch' ? ' ' + : '' + ; + my $group = sub { my $list = shift; '-' . ( @$list == 1 ? $list->[0] : '[' . join( '|', @$list ) . ']' ); }; my $prepare = sub { my $list = shift; - return ( length $list->[0] > 1 ? '-' : '' ) . $group->($list) if @$list; + return ( length $list->[0] > 1 ? '-' : '' ) . $group->($list) . $value if @$list; return; }; diff --git a/t/11-usage.t b/t/11-usage.t index 2725229..2595aef 100644 --- a/t/11-usage.t +++ b/t/11-usage.t @@ -28,13 +28,13 @@ my $spec = [ my @expectations = ( qr/^Usage: \Q$prog\E \[-rv] \[long options] \[arguments]$/, - qr/^\s+--bare\s*$/, - qr/^\s+--define\s+\(default: arch=i386, isize=4\)$/, - qr/^\s+--input\s+\(default: test\.txt\)$/, - qr/^\s+--libs\s+\(default: one, two\)$/, + qr/^\s+--bare \s*$/, + qr/^\s+--define key=\s+\(default: arch=i386, isize=4\)$/, + qr/^\s+--input \s+\(default: test\.txt\)$/, + qr/^\s+--libs \s+\(default: one, two\)$/, qr/^\s+-r\s+recursive$/, qr/^\s+--test\s+run in test mode$/, - qr/^\s+-v, --verbose\s+turn on verbose output \(default: 2\)$/, + qr/^\s+-v \[\], --verbose \[\]\s+turn on verbose output \(default: 2\)$/, ); plan tests => 2 + @expectations;