diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-09-06 08:10:45 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-09-06 08:10:45 +0300 |
commit | 14504db91c95949df7973f97aba7ab0a6a35c520 (patch) | |
tree | 8970c17c47106a1c26986c51831a19a4b467c436 | |
parent | 29ebe894780dd5384bef00af34b81eecb01343e9 (diff) | |
download | rex-14504db91c95949df7973f97aba7ab0a6a35c520.tar.gz rex-14504db91c95949df7973f97aba7ab0a6a35c520.tar.bz2 |
Clean up the config namespace
-rwxr-xr-x | rex.exp | 58 |
1 files changed, 31 insertions, 27 deletions
@@ -1528,13 +1528,13 @@ if [info exists config(option,encrypt)] { exit 0 } -set cfgvars { sudo hosts user password command program } namespace eval config { variable initialized 0 + variable cfgvars {sudo hosts user password command program} - proc readcfg {file} { - global cfgvars config + proc read {file} { + variable cfgvars variable initialized foreach var $cfgvars { variable $var @@ -1542,14 +1542,35 @@ namespace eval config { source $file set initialized 1 } - proc cfgexists {name} { + proc exists {name} { variable $name info exists $name } - proc cfgvar {name} { + proc valueof {name} { variable $name eval { return [set $name] } } + proc export {} { + global config + variable cfgvars + variable initialized + foreach var $cfgvars { + if [exists $var] { + if [info exists config($var)] { + if {$var == "hosts" && + ![info exists config(option,ignore-hosts)]} { + set hosts [valueof hosts] + lappend hosts {*}$config(hosts) + set config(hosts) $hosts + debug 3 "config(hosts) = $config(hosts)" + } + } else { + eval { set config($var) [valueof $var] } + debug 3 "config($var) = $config($var)" + } + } + } + } } proc scanlibpath {file} { @@ -1580,13 +1601,13 @@ array unset rexdb updated if {![info exists config(option,no-init-file)]} { if [file exists config(file)] { debug 2 "reading configuration file $config(file)" - ::config::readcfg $config(file) + ::config::read $config(file) } else { foreach dir [lreverse $confpath] { set cfg "$dir/rc" if [file exists $cfg] { debug 2 "reading configuration file $cfg" - ::config::readcfg $cfg + ::config::read $cfg } } } @@ -1597,7 +1618,7 @@ if [info exists config(option,hostgroup)] { set cfg "$dir/hostgroup/[config_option hostgroup]/rc" if [file exists $cfg] { debug 2 "reading configuration file $cfg" - ::config::readcfg $cfg + ::config::read $cfg break } } @@ -1618,25 +1639,8 @@ if [info exists config(script)] { } } -if {$config::initialized} { - debug 2 "importing configuration settings" - foreach var $cfgvars { - if [::config::cfgexists $var] { - if [info exists config($var)] { - if {$var == "hosts" && - ![info exists config(option,ignore-hosts)]} { - set hosts [::config::cfgvar hosts] - lappend hosts {*}$config(hosts) - set config(hosts) $hosts - debug 3 "config(hosts) = $config(hosts)" - } - } else { - eval { set config($var) [::config::cfgvar $var] } - debug 3 "config($var) = $config($var)" - } - } - } -} +debug 2 "importing configuration settings" +::config::export debug 2 "running prologue script" ::hostproc::prologue |