1 # Copyright (C) 2021 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3 package PublicInbox::LeiConfig;
6 use PublicInbox::PktOp;
8 sub cfg_do_edit ($;$) {
9 my ($self, $reason) = @_;
10 my $lei = $self->{lei};
11 $lei->pgr_err($reason) if defined $reason;
12 my $cmd = [ qw(git config --edit -f), $self->{-f} ];
13 my $env = { GIT_CONFIG => $self->{-f} };
14 $self->cfg_edit_begin if $self->can('cfg_edit_begin');
15 # run in script/lei foreground
16 my ($op_c, $op_p) = PublicInbox::PktOp->pair;
17 # $op_p will EOF when $EDITOR is done
18 $op_c->{ops} = { '' => [\&cfg_edit_done, $self] };
19 $lei->send_exec_cmd([ @$lei{qw(0 1 2)}, $op_p->{op_p} ], $cmd, $env);
22 sub cfg_edit_done { # PktOp
25 my $cfg = $self->{lei}->cfg_dump($self->{-f}, $self->{lei}->{2})
26 // return cfg_do_edit($self, "\n");
27 $self->cfg_verify($cfg) if $self->can('cfg_verify');
29 $self->{lei}->fail($@) if $@;
33 my ($lei, @argv) = @_;
34 $lei->{opt}->{'config-file'} and return $lei->fail(
35 "config file switches not supported by `lei config'");
36 return $lei->_config(@argv) unless $lei->{opt}->{edit};
37 my $f = $lei->_lei_cfg(1)->{-f};
38 my $self = bless { lei => $lei, -f => $f }, __PACKAGE__;