user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* JSON field names in terminal/pager output
@ 2021-01-05  9:56  6% Eric Wong
  0 siblings, 0 replies; 3+ results
From: Eric Wong @ 2021-01-05  9:56 UTC (permalink / raw)
  To: meta

Are "f", "s", "t", "c" acceptable field names to show in JSON
output?  (instead of from/subject/to/cc)

The single-chars have been used in the search queries for as
long as we've had search.  And I stole that UI bit from
mairix(1), so there's prior art.

Anyways, the current JSON output looks something like the
following, comments inline

[{
  "blob": "d21717dae7e18dbc9efcd5ca57fe2ee92747bc06",
  "docid": 41946,
  "dt": "2021-01-05T09:24:49Z",

  # dt: is not an exact match for current WWW behavior which
  # needs YYYYMMDDHHMMSS (all digits).  Getting Xapian to parse
  # dates from Perl (w/o custom C++) isn't possible, yet.
  # dt: is the date header, "UTCDate" in JMAP.

  "f": "Eric Wong <e@80x24.org>",

  # "from": might be more obvious, but seeing it thousands of
  # times every message might be too much

  "m": "<20210105092449.GA22853@dcvr>",

  # mid/msgid/message-id

  "rcvd": "2021-01-05T09:24:49Z",
  # IMAP calls this INTERNALDATE, JMAP calls it "receivedAt"

  "references": [
    "<20210105090437.22801-1-e@80x24.org>",
    "<20210105090437.22801-5-e@80x24.org>"
  ],

  # we don't actually support searching on rereference, yet;
  # not sure if it's needed since we already do thread # expansion

  "relevance": 13,

  # relevance is ->get_percent from Xapian

  "s": "JSON pretty-printing [was: [4/4] ... (and maybe lei)]",
  "t": "meta@public-inbox.org"

  # Subject and To: headers
}, {
  # Another message, we do "}, {" to save vertical white space
  rather than "},\n{"

  "blob": "0ee1d7d9ec9b29c1d8f103033ed06e9e48e6ebfe",
  "docid": 41930,

  # side note: it's probably not worth displaying docid for
  # ephemeral search indices like LeiXSearch

  "dt": "2021-01-05T09:04:36Z",
  "f": "Eric Wong <e@80x24.org>",
  "m": "<20210105090437.22801-4-e@80x24.org>",
  "rcvd": "2021-01-05T09:04:38Z",
  "references": [
    "<20210105090437.22801-1-e@80x24.org>"
  ],
  "relevance": 36,
  "s": "[PATCH 3/4] lei: use client env as-is, drop daemon-env command",
  "t": "meta@public-inbox.org"
}, {


...

^ permalink raw reply	[relevance 6%]

* [PATCH 3/4] lei: use client env as-is, drop daemon-env command
  2021-01-05  9:04  6% [PATCH 0/4] more lei usability stuff Eric Wong
@ 2021-01-05  9:04  7% ` Eric Wong
  0 siblings, 0 replies; 3+ results
From: Eric Wong @ 2021-01-05  9:04 UTC (permalink / raw)
  To: meta

There may be subtle misbehaviours when mixing the existing
daemon env and the client-supplied env.  Just do the simplest
thing and use the client env as-is.

We'll also start the ->event_step callback since we'll need
to remember some things for long-lived commands.
---
 lib/PublicInbox/LEI.pm | 38 ++++++++++++--------------------------
 t/lei.t                | 30 +-----------------------------
 2 files changed, 13 insertions(+), 55 deletions(-)

diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index 6073a713..9c3308ad 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -149,8 +149,6 @@ our %CMD = ( # sorted in order of importance/use:
 'daemon-kill' => [ '[-SIGNAL]', 'signal the lei-daemon',
 	opt_dash('signal|s=s', '[0-9]+|(?:[A-Z][A-Z0-9]+)') ],
 'daemon-pid' => [ '', 'show the PID of the lei-daemon' ],
-'daemon-env' => [ '[NAME=VALUE...]', 'set, unset, or show daemon environment',
-	qw(clear| unset|u=s@ z|0) ],
 'help' => [ '[SUBCOMMAND]', 'show help' ],
 
 # XXX do we need this?
@@ -230,12 +228,6 @@ my %OPTDESC = (
 # xargs, env, use "-0", git(1) uses "-z".  We support z|0 everywhere
 'z|0' => 'use NUL \\0 instead of newline (CR) to delimit lines',
 
-# note: no "--ignore-environment" / "-i" support like env(1) since that
-# is one-shot and this is for a persistent daemon:
-'clear|' => 'clear the daemon environment',
-'unset|u=s@' => ['NAME',
-	'unset matching NAME, may be specified multiple times'],
-
 'signal|s=s' => [ 'SIG', 'signal to send lei-daemon (default: TERM)' ],
 ); # %OPTDESC
 
@@ -538,24 +530,6 @@ sub lei_daemon_kill {
 	kill($sig, $$) or fail($self, "kill($sig, $$): $!");
 }
 
-sub lei_daemon_env {
-	my ($self, @argv) = @_;
-	my $opt = $self->{opt};
-	if (defined $opt->{clear}) {
-		%ENV = ();
-	} elsif (my $u = $opt->{unset}) {
-		delete @ENV{@$u};
-	}
-	if (@argv) {
-		%ENV = (%ENV, map { split(/=/, $_, 2) } @argv);
-	} elsif (!defined($opt->{clear}) && !$opt->{unset}) {
-		my $eor = $opt->{z} ? "\0" : "\n";
-		my $buf = '';
-		while (my ($k, $v) = each %ENV) { $buf .= "$k=$v$eor" }
-		out $self, $buf;
-	}
-}
-
 sub lei_help { _help($_[0]) }
 
 # Shell completion helper.  Used by lei-completion.bash and hopefully
@@ -678,6 +652,7 @@ sub accept_dispatch { # Listener {post_accept} callback
 	};
 	my %env = map { split(/=/, $_, 2) } split(/\0/, $env);
 	if (chdir($env{PWD})) {
+		local %ENV = %env;
 		$self->{env} = \%env;
 		$self->{pid} = $client_pid;
 		eval { dispatch($self, split(/\]\0\[/, $argv)) };
@@ -687,6 +662,17 @@ sub accept_dispatch { # Listener {post_accept} callback
 	}
 }
 
+# for long-running results
+sub event_step {
+	my ($self) = @_;
+	local %ENV = %{$self->{env}};
+	eval {}; # TODO
+	if ($@) {
+		say { $self->{sock} } $@;
+		$self->close; # PublicInbox::DS::close
+	}
+}
+
 sub noop {}
 
 # lei(1) calls this when it can't connect
diff --git a/t/lei.t b/t/lei.t
index 5afb8351..6d47e307 100644
--- a/t/lei.t
+++ b/t/lei.t
@@ -192,7 +192,7 @@ if ($ENV{TEST_LEI_ONESHOT}) {
 }
 
 SKIP: { # real socket
-	require_mods(qw(Cwd), my $nr = 46);
+	require_mods(qw(Cwd), my $nr = 105);
 	my $nfd = eval { require IO::FDPass; 1 } // do {
 		require PublicInbox::Spawn;
 		PublicInbox::Spawn->can('send_3fds') ? 3 : undef;
@@ -215,34 +215,6 @@ SKIP: { # real socket
 	chomp(my $pid_again = $out);
 	is($pid, $pid_again, 'daemon-pid idempotent');
 
-	ok($lei->(qw(daemon-env -0)), 'show env');
-	is($err, '', 'no errors in env dump');
-	my @env = split(/\0/, $out);
-	is(scalar grep(/\AHOME=\Q$home\E\z/, @env), 1, 'env has HOME');
-	is(scalar grep(/\AFOO=BAR\z/, @env), 1, 'env has FOO=BAR');
-	is(scalar grep(/\AXDG_RUNTIME_DIR=/, @env), 1, 'has XDG_RUNTIME_DIR');
-
-	ok($lei->(qw(daemon-env -u FOO)), 'unset');
-	is($out.$err, '', 'no output for unset');
-	ok($lei->(qw(daemon-env -0)), 'show again');
-	is($err, '', 'no errors in env dump');
-	@env = split(/\0/, $out);
-	is(scalar grep(/\AFOO=BAR\z/, @env), 0, 'env unset FOO');
-
-	ok($lei->(qw(daemon-env -u FOO -u HOME -u XDG_RUNTIME_DIR)),
-			'unset multiple');
-	is($out.$err, '', 'no errors output for unset');
-
-	ok($lei->(qw(daemon-env -0)), 'show again');
-	is($err, '', 'no errors in env dump');
-	@env = split(/\0/, $out);
-	is(scalar grep(/\A(?:HOME|XDG_RUNTIME_DIR)=\z/, @env), 0, 'env unset@');
-
-	ok($lei->(qw(daemon-env -)), 'clear env');
-	is($out.$err, '', 'no output');
-	ok($lei->(qw(daemon-env)), 'env is empty');
-	is($out, '', 'env cleared');
-
 	ok($lei->(qw(daemon-kill)), 'daemon-kill');
 	is($out, '', 'no output from daemon-kill');
 	is($err, '', 'no error from daemon-kill');

^ permalink raw reply related	[relevance 7%]

* [PATCH 0/4] more lei usability stuff
@ 2021-01-05  9:04  6% Eric Wong
  2021-01-05  9:04  7% ` [PATCH 3/4] lei: use client env as-is, drop daemon-env command Eric Wong
  0 siblings, 1 reply; 3+ results
From: Eric Wong @ 2021-01-05  9:04 UTC (permalink / raw)
  To: meta

Eric Wong (4):
  lei: completion: fix filename completion
  lei: automatic pager support
  lei: use client env as-is, drop daemon-env command
  address: pairs: new helper for JMAP (and maybe lei)

 contrib/completion/lei-completion.bash |  2 +-
 lib/PublicInbox/Address.pm             | 11 ++++-
 lib/PublicInbox/AddressPP.pm           | 21 ++++++++
 lib/PublicInbox/LEI.pm                 | 68 +++++++++++++++-----------
 t/address.t                            | 33 ++++++++++---
 t/lei.t                                | 30 +-----------
 6 files changed, 100 insertions(+), 65 deletions(-)

^ permalink raw reply	[relevance 6%]

Results 1-3 of 3 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2021-01-05  9:04  6% [PATCH 0/4] more lei usability stuff Eric Wong
2021-01-05  9:04  7% ` [PATCH 3/4] lei: use client env as-is, drop daemon-env command Eric Wong
2021-01-05  9:56  6% JSON field names in terminal/pager output Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).