From f170d220f8765e952c9a102dd35eb694810739df Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 24 Sep 2023 05:42:13 +0000 Subject: lei: fix `-c NAME=VALUE' config support We can pass `-c NAME=VALUE' args directly to git-config without needing a temporary directory nor file. Furthermore, this opens the door to us being able to correctly handle `-c NAME=VALUE' after `delete $lei->{cfg}' if we need to reload the config during a command. This tightens up error-checking for `lei config' and ensures we can make config settings changes while using `-c NAME=VALUE' instead of editing the temporary file. The non-obvious part was avoiding the use of the -f/--file arg for `git config' for read-only operations and include relying on `-c include.path=$ABS_PATH'. This is done by parsing the switches to be passed to `git config' to determine if it's a read-only operation or not. --- lib/PublicInbox/LeiConfig.pm | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'lib/PublicInbox/LeiConfig.pm') diff --git a/lib/PublicInbox/LeiConfig.pm b/lib/PublicInbox/LeiConfig.pm index fd4b0eca..76fc43e7 100644 --- a/lib/PublicInbox/LeiConfig.pm +++ b/lib/PublicInbox/LeiConfig.pm @@ -1,8 +1,7 @@ -# Copyright (C) 2021 all contributors +# Copyright (C) all contributors # License: AGPL-3.0+ -package PublicInbox::LeiConfig; -use strict; -use v5.10.1; +package PublicInbox::LeiConfig; # subclassed by LeiEditSearch +use v5.12; use PublicInbox::PktOp; use Fcntl qw(SEEK_SET); use autodie qw(open seek); @@ -41,10 +40,18 @@ sub lei_config { my ($lei, @argv) = @_; $lei->{opt}->{'config-file'} and return $lei->fail( "config file switches not supported by `lei config'"); - return $lei->_config(@argv) unless $lei->{opt}->{edit}; - my $f = $lei->_lei_cfg(1)->{-f}; - my $self = bless { lei => $lei, -f => $f }, __PACKAGE__; - cfg_do_edit($self); + if ($lei->{opt}->{edit}) { + @argv and return $lei->fail( +'--edit must be used without other arguments'); + $lei->{opt}->{c} and return $lei->fail( +"`-c $lei->{opt}->{c}->[0]' not allowed with --edit"); + my $f = $lei->_lei_cfg(1)->{-f}; + cfg_do_edit(bless { lei => $lei, -f => $f }, __PACKAGE__); + } elsif (@argv) { # let git-config do error-checking + $lei->_config(@argv); + } else { + $lei->_help('no options given'); + } } 1; -- cgit v1.2.3-24-ge0c7