unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH 0/2] lei: some usage bits
@ 2021-01-04  4:16 Eric Wong
  2021-01-04  4:16 ` [PATCH 1/2] lei: fix opt_dash to pass non-dash args to @argv Eric Wong
  2021-01-04  4:16 ` [PATCH 2/2] lei: improve idempotent "init" error message Eric Wong
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Wong @ 2021-01-04  4:16 UTC (permalink / raw)
  To: meta

Still trying to wrap my head around xsearch but my head hurts :<

Eric Wong (2):
  lei: fix opt_dash to pass non-dash args to @argv
  lei: improve idempotent "init" error message

 lib/PublicInbox/LEI.pm | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] lei: fix opt_dash to pass non-dash args to @argv
  2021-01-04  4:16 [PATCH 0/2] lei: some usage bits Eric Wong
@ 2021-01-04  4:16 ` Eric Wong
  2021-01-04  4:16 ` [PATCH 2/2] lei: improve idempotent "init" error message Eric Wong
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2021-01-04  4:16 UTC (permalink / raw)
  To: meta

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).
---
 lib/PublicInbox/LEI.pm | 17 ++++++++++++++---
 1 file 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;
 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] lei: improve idempotent "init" error message
  2021-01-04  4:16 [PATCH 0/2] lei: some usage bits Eric Wong
  2021-01-04  4:16 ` [PATCH 1/2] lei: fix opt_dash to pass non-dash args to @argv Eric Wong
@ 2021-01-04  4:16 ` Eric Wong
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2021-01-04  4:16 UTC (permalink / raw)
  To: meta

Showing "leistore.dir= already initialized" because $cur is
undefined isn't useful.
---
 lib/PublicInbox/LEI.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index 50453dde..9a3b1ee3 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -505,7 +505,7 @@ sub lei_init {
 	$dir //= _store_path($env);
 	$dir = File::Spec->rel2abs($dir, $env->{PWD}); # PWD is symlink-aware
 	my @cur = stat($cur) if defined($cur);
-	$cur = File::Spec->canonpath($cur) if $cur;
+	$cur = File::Spec->canonpath($cur // $dir);
 	my @dir = stat($dir);
 	my $exists = "I: leistore.dir=$cur already initialized" if @dir;
 	if (@cur) {

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-01-04  4:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-04  4:16 [PATCH 0/2] lei: some usage bits Eric Wong
2021-01-04  4:16 ` [PATCH 1/2] lei: fix opt_dash to pass non-dash args to @argv Eric Wong
2021-01-04  4:16 ` [PATCH 2/2] lei: improve idempotent "init" error message Eric Wong

unofficial mirror of meta@public-inbox.org

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhetil.org/meta

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 meta meta/ https://yhetil.org/meta \
		meta@public-inbox.org
	public-inbox-index meta

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.mail.public-inbox.meta
	nntp://news.public-inbox.org/inbox.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general


AGPL code for this site: git clone http://ou63pmih66umazou.onion/public-inbox.git