diff options
author | Eric Wong <e@80x24.org> | 2021-04-18 08:40:14 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-04-18 19:04:42 -0400 |
commit | 2018db2a23ab1d949c757c264534f39dba338ccb (patch) | |
tree | 86a06bda17018b97d760d579aa7214f68e1ab42e /lib/PublicInbox/LeiSavedSearch.pm | |
parent | 3b7b5442c4321ae802867cbda9bd33235ab2a5a3 (diff) | |
download | public-inbox-2018db2a23ab1d949c757c264534f39dba338ccb.tar.gz |
Going forward, we'll probably support JSON for all the "ls-*" subcommands. This also provides the basis for "lei up" shell completion.
Diffstat (limited to 'lib/PublicInbox/LeiSavedSearch.pm')
-rw-r--r-- | lib/PublicInbox/LeiSavedSearch.pm | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/lib/PublicInbox/LeiSavedSearch.pm b/lib/PublicInbox/LeiSavedSearch.pm index 3076d14c..d67622c9 100644 --- a/lib/PublicInbox/LeiSavedSearch.pm +++ b/lib/PublicInbox/LeiSavedSearch.pm @@ -21,6 +21,11 @@ sub cquote_val ($) { # cf. git-config(1) $val; } +sub ARRAY_FIELDS () { qw(only include exclude) } +sub BOOL_FIELDS () { + qw(external local remote import-remote import-before threads) +} + sub lss_dir_for ($$) { my ($lei, $dstref) = @_; my @n; @@ -39,6 +44,31 @@ sub lss_dir_for ($$) { $lei->share_path . '/saved-searches/' . join('-', @n); } +sub list { + my ($lei, $pfx) = @_; + my $lss_dir = $lei->share_path.'/saved-searches/'; + return () unless -d $lss_dir; + # TODO: persist the cache? Use another format? + my $f = $lei->cache_dir."/saved-tmp.$$.".time.'.config'; + open my $fh, '>', $f or die "open $f: $!"; + print $fh "[include]\n"; + for my $p (glob("$lss_dir/*/lei.saved-search")) { + print $fh "\tpath = ", cquote_val($p), "\n"; + } + close $fh or die "close $f: $!"; + my $cfg = PublicInbox::Config::git_config_dump($f); + unlink($f); + bless $cfg, 'PublicInbox::Config'; + my $out = $cfg->get_all('lei.q.output') or return (); + map {; + if (s!\A(?:maildir|mh|mbox.+|mmdf):!!i) { + -e $_ ? $_ : (); # TODO auto-prune somewhere? + } else { # IMAP, maybe JMAP + $_; + } + } @$out +} + sub new { my ($cls, $lei, $dst) = @_; my $self = bless { ale => $lei->ale }, $cls; @@ -74,16 +104,15 @@ $q [lei "q"] output = $dst EOM - for my $k (qw(only include exclude)) { + for my $k (ARRAY_FIELDS) { my $ary = $lei->{opt}->{$k} // next; for my $x (@$ary) { print $fh "\t$k = ".cquote_val($x)."\n"; } } - for my $k (qw(external local remote import-remote - import-before threads)) { + for my $k (BOOL_FIELDS) { my $val = $lei->{opt}->{$k} // next; - print $fh "\t$k = ".cquote_val($val)."\n"; + print $fh "\t$k = ".($val ? 1 : 0)."\n"; } close($fh) or return $lei->fail("close $f: $!"); } |