public-inbox.git  about / heads / tags
an "archives first" approach to mailing lists
blob e2be5ceef18c84bb756b5cce6c4be02f3dbc570b 1224 bytes (raw)
$ git show HEAD:lib/PublicInbox/LeiAddWatch.pm	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 
# Copyright all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>

# "lei add-watch" command
package PublicInbox::LeiAddWatch;
use strict;
use v5.10.1;
use parent qw(PublicInbox::LeiInput);

sub lei_add_watch {
	my ($lei, @argv) = @_;
	my $cfg = $lei->_lei_cfg(1);
	my $self = bless {}, __PACKAGE__;
	$lei->{opt}->{'mail-sync'} = 1; # for prepare_inputs
	my $state = $lei->{opt}->{'state'} // 'import-rw';
	$lei->watch_state_ok($state) or
		return $lei->fail("invalid state: $state");
	$self->prepare_inputs($lei, \@argv) or return;
	my @vmd;
	while (my ($type, $vals) = each %{$lei->{vmd_mod}}) {
		push @vmd, "$type:$_" for @$vals;
	}
	my $vmd0 = shift @vmd;
	for my $w (@{$self->{inputs}}) {
		# clobber existing, allow multiple
		if (defined($vmd0)) {
			$lei->_config("watch.$w.vmd", '--replace-all', $vmd0)
				or return;
			for my $v (@vmd) {
				$lei->_config("watch.$w.vmd", $v) or return;
			}
		}
		next if defined $cfg->{"watch.$w.state"};
		$lei->_config("watch.$w.state", $state) or return;
	}
	$lei->_lei_store(1); # create
	$lei->lms(1)->lms_write_prepare->add_folders(@{$self->{inputs}});
	delete $lei->{cfg}; # force reload
	$lei->refresh_watches;
}

1;

git clone https://public-inbox.org/public-inbox.git
git clone http://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/public-inbox.git