From: Ian Jackson Date: Thu, 18 Jun 2020 14:45:59 +0000 (+0100) Subject: nailing-carog: Read configuration X-Git-Tag: nailing-cargo/1.0.0~180 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=0da64ac3b548e16576b9be69590f22b054d0bfb9;p=nailing-cargo.git nailing-carog: Read configuration Actually call loadconfigs. Make it sensible. And use its output. Signed-off-by: Ian Jackson --- diff --git a/nailing-cargo b/nailing-cargo index 6511612..d030111 100755 --- a/nailing-cargo +++ b/nailing-cargo @@ -108,7 +108,15 @@ # = # = { = ... } # -# To control use of alternative Cargo.lock filename: +# Configuration is read from +# +# /etc/nailing-cargo/cfg.toml +# ~/.nailing-cargo.toml +# ./.nailing-cargo.toml +# ../Nailing-Cargo.toml +# ../Cargo.nail +# +# To control use of alternative Cargo.lock filename: # [alt_cargolock] # # file = true # equivalent to "Cargo.lock.example" @@ -244,6 +252,7 @@ sub stat_exists ($$) { sub toml_or_enoent ($$) { my ($f,$what) = @_; my $toml = read_or_enoent($f) // return; + print STDERR "Read TOML from $f\n" if $dump; my ($v,$e) = from_toml($toml); if (!defined $v) { chomp $e; @@ -260,19 +269,11 @@ sub load1config ($) { } sub loadconfigs () { - my $cfgleaf = ".nailing-cargo-cfg.toml"; + my $dotfile = ".nailing-cargo.toml"; + load1config("../Nailing-Cargo.toml"); + load1config($dotfile); + load1config("$ENV{HOME}/$dotfile") if defined $ENV{HOME}; load1config("/etc/nailing-cargo/cfg.toml"); - load1config("$worksphere/$cfgleaf"); - load1config("$ENV{HOME}/$cfgleaf") if defined $ENV{HOME}; -} - -sub getcfg ($$) { - my ($k, $def) = @_; - foreach my $cfg (@configs) { - my $v = $cfg->{$k}; - return $v if defined $v; - } - return $def; } sub unlink_or_enoent ($) { unlink $_[0] or $!==ENOENT; } @@ -308,13 +309,16 @@ sub badcfg { } sub cfg_uc { - my $v = $nail; - foreach my $k (@_) { - last unless defined $v; - ref($v) eq 'HASH' or badcfg @_, "parent key \`$k' is not a hash"; - $v = $v->{$k}; + foreach my $cfg (@configs) { + my $v = $cfg; + foreach my $k (@_) { + last unless defined $v; + ref($v) eq 'HASH' or badcfg @_, "parent key \`$k' is not a hash"; + $v = $v->{$k}; + } + return $v if defined $v; } - return $v; + return undef; } sub cfge { @@ -388,6 +392,8 @@ sub readnail () { $nail->{subdirs} ]; } + + unshift @configs, $nail; } our @alt_cargo_lock_stat; @@ -851,6 +857,7 @@ while (@ARGV && $ARGV[0] =~ m/^-/) { die "$self: need command to run\n" unless @ARGV || $noact; +loadconfigs(); takelock(); readnail(); consider_alt_cargo_lock();