diff options
author | Eric Wong <e@80x24.org> | 2021-04-19 08:52:14 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-04-19 20:15:59 +0000 |
commit | f9d6b4a0f5f66a084682aba229b44ef47afdfc35 (patch) | |
tree | 0f9bdb02d56a88e3afee717cf4d25e76c1cfbff0 /lib/PublicInbox/LeiSavedSearch.pm | |
parent | ab42b22acfd9670df0b61f514b4fb89fe7754846 (diff) | |
download | public-inbox-f9d6b4a0f5f66a084682aba229b44ef47afdfc35.tar.gz |
They're more different than alike, and having two separate methods seems less confusing to me.
Diffstat (limited to 'lib/PublicInbox/LeiSavedSearch.pm')
-rw-r--r-- | lib/PublicInbox/LeiSavedSearch.pm | 79 |
1 files changed, 42 insertions, 37 deletions
diff --git a/lib/PublicInbox/LeiSavedSearch.pm b/lib/PublicInbox/LeiSavedSearch.pm index d3a32d36..948e4954 100644 --- a/lib/PublicInbox/LeiSavedSearch.pm +++ b/lib/PublicInbox/LeiSavedSearch.pm @@ -65,52 +65,57 @@ sub list { } @$out } -sub new { +sub up { # updating existing saved search via "lei up" my ($cls, $lei, $dst) = @_; + my $f; my $self = bless { ale => $lei->ale }, $cls; - my $dir; - if (defined $dst) { # updating existing saved search via "lei up" - my $f; - $dir = $dst; - output2lssdir($self, $lei, \$dir, \$f) or - return $lei->fail("--save was not used with $dst cwd=". - $lei->rel2abs('.')); - $self->{'-f'} = $f; - } else { # new saved search "lei q --save" - $dst = $lei->{ovv}->{dst}; - $dir = lss_dir_for($lei, \$dst); - require File::Path; - File::Path::make_path($dir); # raises on error - $self->{-cfg} = {}; - my $f = $self->{'-f'} = "$dir/lei.saved-search"; - open my $fh, '>', $f or return $lei->fail("open $f: $!"); - my $sq_dst = PublicInbox::Config::squote_maybe($dst); - my $q = $lei->{mset_opt}->{q_raw} // die 'BUG: {q_raw} missing'; - if (ref $q) { - $q = join("\n", map { "\tq = ".cquote_val($_) } @$q); - } else { - $q = "\tq = ".cquote_val($q); - } - $dst = "$lei->{ovv}->{fmt}:$dst" if $dst !~ m!\Aimaps?://!i; - print $fh <<EOM; + my $dir = $dst; + output2lssdir($self, $lei, \$dir, \$f) or + return $lei->fail("--save was not used with $dst cwd=". + $lei->rel2abs('.')); + $self->{-cfg} = PublicInbox::Config->git_config_dump($f); + $self->{-ovf} = "$dir/over.sqlite3"; + $self->{'-f'} = $f; + $self->{lock_path} = "$self->{-f}.flock"; + $self; +} + +sub new { # new saved search "lei q --save" + my ($cls, $lei) = @_; + my $self = bless { ale => $lei->ale }, $cls; + my $dst = $lei->{ovv}->{dst}; + my $dir = lss_dir_for($lei, \$dst); + require File::Path; + File::Path::make_path($dir); # raises on error + $self->{-cfg} = {}; + my $f = $self->{'-f'} = "$dir/lei.saved-search"; + open my $fh, '>', $f or return $lei->fail("open $f: $!"); + my $sq_dst = PublicInbox::Config::squote_maybe($dst); + my $q = $lei->{mset_opt}->{q_raw} // die 'BUG: {q_raw} missing'; + if (ref $q) { + $q = join("\n", map { "\tq = ".cquote_val($_) } @$q); + } else { + $q = "\tq = ".cquote_val($q); + } + $dst = "$lei->{ovv}->{fmt}:$dst" if $dst !~ m!\Aimaps?://!i; + print $fh <<EOM; ; to refresh with new results, run: lei up $sq_dst [lei] -$q + $q [lei "q"] output = $dst EOM - 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 (BOOL_FIELDS) { - my $val = $lei->{opt}->{$k} // next; - print $fh "\t$k = ".($val ? 1 : 0)."\n"; + for my $k (ARRAY_FIELDS) { + my $ary = $lei->{opt}->{$k} // next; + for my $x (@$ary) { + print $fh "\t$k = ".cquote_val($x)."\n"; } - close($fh) or return $lei->fail("close $f: $!"); } + for my $k (BOOL_FIELDS) { + my $val = $lei->{opt}->{$k} // next; + print $fh "\t$k = ".($val ? 1 : 0)."\n"; + } + close($fh) or return $lei->fail("close $f: $!"); $self->{lock_path} = "$self->{-f}.flock"; $self->{-ovf} = "$dir/over.sqlite3"; $self; |