Subject: | PATCH: broken short option list in usage |
With a spec like 'list|l=s@', 'l' won't show up in the short options of
the usage because the regex used doesn't match the @.
Attached a patch with test that should be more complete for the various
Getopt::Long option specifiers.
Regards,
Bradley C Bailey
Subject: | gld-short-options.patch |
diff -ruN Getopt-Long-Descriptive-0.070.orig/lib/Getopt/Long/Descriptive.pm Getopt-Long-Descriptive-0.070/lib/Getopt/Long/Descriptive.pm
--- Getopt-Long-Descriptive-0.070.orig/lib/Getopt/Long/Descriptive.pm 2008-01-29 13:39:11.000000000 -0700
+++ Getopt-Long-Descriptive-0.070/lib/Getopt/Long/Descriptive.pm 2008-03-17 01:18:52.000000000 -0600
@@ -295,10 +295,13 @@
$_->{desc} ne 'spacer'
} _nohidden(@opts);
+
+ my $spec_assignment = '(?:[:=][\d\w\+]+[%@]?({\d*,\d*})?|[!+])$';
+
my $short = join "", sort {
lc $a cmp lc $b
} map {
- (my $s = $_) =~ s/([:=]\w+|!)$//;
+ (my $s = $_) =~ s/$spec_assignment//;
grep /^.$/, split /\|/, $s
} @specs;
@@ -343,7 +346,7 @@
printf {$out_fh} "$spec_fmt\n", $opt->{spec};
next;
}
- $spec =~ s/([:=]\w+[%@]?|!)$//;
+ $spec =~ s/$spec_assignment//;
$spec = join " ", reverse map { length > 1 ? "--$_" : "-$_" }
split /\|/, $spec;
printf {$out_fh} "$spec_fmt %s\n", $spec, $desc;
diff -ruN Getopt-Long-Descriptive-0.070.orig/t/descriptive.t Getopt-Long-Descriptive-0.070/t/descriptive.t
--- Getopt-Long-Descriptive-0.070.orig/t/descriptive.t 2008-01-29 13:36:50.000000000 -0700
+++ Getopt-Long-Descriptive-0.070/t/descriptive.t 2008-03-17 01:25:13.000000000 -0600
@@ -124,6 +124,7 @@
[ [ mode => $foobar ] ],
#qr/\Qonly one 'mode' option (foo, bar)\E/,
qr/it is 'foo' already/,
+ "only one 'mode' option",
);
is_opt(
@@ -169,6 +170,26 @@
}
{
+ local @ARGV;
+ my ($opt, $usage) = describe_options(
+ "%c %o",
+ [ 'foo' => "foo option" ],
+ [ 'bar|b' => "bar option" ],
+ [ 'string|s=s' => "string value" ],
+ [ 'string|S:s' => "optional string value" ],
+ [ 'list|l=s@' => "list of strings" ],
+ [ 'hash|h=s%' => "hash values" ],
+ [ 'optional|o!' => "optional" ],
+ [ 'increment|i+' => "incremental option" ],
+ );
+ like(
+ $usage->text,
+ qr/\[-bhilosS\]/,
+ "short options",
+ );
+}
+
+{
local @ARGV = qw(--foo);
my ($opt, $usage) = describe_options(
"%c %o",