about summary refs log tree commit homepage
path: root/lib/PublicInbox/LeiConfig.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-09-24 05:42:13 +0000
committerEric Wong <e@80x24.org>2023-09-24 18:56:08 +0000
commitf170d220f8765e952c9a102dd35eb694810739df (patch)
treeab3baa8c8c2775f2b74da1f871980603da19586d /lib/PublicInbox/LeiConfig.pm
parentb4b22d40c52584836d7c0c97a513dfac1c12fbee (diff)
downloadpublic-inbox-f170d220f8765e952c9a102dd35eb694810739df.tar.gz
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.
Diffstat (limited to 'lib/PublicInbox/LeiConfig.pm')
-rw-r--r--lib/PublicInbox/LeiConfig.pm23
1 files changed, 15 insertions, 8 deletions
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 <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
-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;