diff options
author | Eric Wong <e@80x24.org> | 2021-01-04 04:16:23 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-01-04 19:00:47 +0000 |
commit | 2ea2b609f46a51bab56bccb7cbc93c27b8a3b5a6 (patch) | |
tree | 76556e9d67a07c00873b9dc0b657902417f9f990 /lib | |
parent | 7c73a09c6df674e389fb20fb57f63c6bb9695d31 (diff) | |
download | public-inbox-2ea2b609f46a51bab56bccb7cbc93c27b8a3b5a6.tar.gz |
The special "<>" handling in Getopt::Long actually invokes the callback for every single command-line arg, not just those prefixed by "-". This will let us pass arbitrary non-dashed words for search queries so users can type queries naturally without quoting (unless they want phrase search).
Diffstat (limited to 'lib')
-rw-r--r-- | lib/PublicInbox/LEI.pm | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index f41f63ed..50453dde 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -38,18 +38,27 @@ our %PATH2CFG; # persistent for socket daemon sub pass_through { $GLP_PASS } my $OPT; -sub opt_dash { +sub opt_dash ($$) { my ($spec, $re_str) = @_; # 'limit|n=i', '([0-9]+)' my ($key) = ($spec =~ m/\A([a-z]+)/g); my $cb = sub { # Getopt::Long "<>" catch-all handler my ($arg) = @_; if ($arg =~ /\A-($re_str)\z/) { $OPT->{$key} = $1; + } elsif ($arg eq '--') { # "--" arg separator, ignore first + push @{$OPT->{-argv}}, $arg if $OPT->{'--'}++; + # lone (single) dash is handled elsewhere + } elsif (substr($arg, 0, 1) eq '-') { + if ($OPT->{'--'}) { + push @{$OPT->{-argv}}, $arg; + } else { + die "bad argument: $arg\n"; + } } else { - die "bad argument for --$key: $arg\n"; + push @{$OPT->{-argv}}, $arg; } }; - ($spec, '<>' => $cb, $GLP_PASS) + ($spec, '<>' => $cb, $GLP_PASS) # for Getopt::Long } sub _store_path ($) { @@ -360,6 +369,8 @@ sub optparse ($$$) { return _help($self, "bad arguments or options for $cmd"); return _help($self) if $OPT->{help}; + push @$argv, @{$OPT->{-argv}} if defined($OPT->{-argv}); + # "-" aliases "stdin" or "clear" $OPT->{$lone_dash} = ${$OPT->{$lone_dash}} if defined $lone_dash; |