environ configuration

This commit is contained in:
Pavel Vorobyov
2019-09-24 16:06:20 +03:00
parent e4d225c825
commit 262f4ac873
2 changed files with 17 additions and 0 deletions

View File

@@ -94,6 +94,7 @@ func New(cfg *config.XCConfig, backend store.Backend) (*Cli, error) {
cli.stopped = false
cli.aliases = make(map[string]*alias)
cli.setupCmdHandlers()
setEnvironment(cfg.LocalEnvironment)
cfg.Readline.AutoComplete = cli.completer
cli.rl, err = readline.NewEx(cfg.Readline)
@@ -267,6 +268,12 @@ func (c *Cli) CmdLoop() {
}
}
func setEnvironment(environ map[string]string) {
for key, value := range environ {
os.Setenv(key, value)
}
}
func (c *Cli) confirm(msg string) bool {
reader := bufio.NewReader(os.Stdin)
for {

View File

@@ -87,6 +87,7 @@ type XCConfig struct {
SuInterpreter string
Interpreter string
PasswordManagerPath string
LocalEnvironment map[string]string
}
const (
@@ -155,6 +156,7 @@ func read(filename string, secondPass bool) (*XCConfig, error) {
cfg := new(XCConfig)
cfg.Readline = defaultReadlineConfig
cfg.BackendCfg = &BackendConfig{Type: BTIni, Options: make(map[string]string)}
cfg.LocalEnvironment = make(map[string]string)
hf, err := props.GetString("main.history_file")
if err != nil {
@@ -316,5 +318,13 @@ func read(filename string, secondPass bool) (*XCConfig, error) {
cfg.PasswordManagerPath, _ = props.GetString("passmgr.path")
envkeys, err := props.Subkeys("environ")
if err == nil {
for _, key := range envkeys {
value, _ := props.GetString(fmt.Sprintf("environ.%s", key))
cfg.LocalEnvironment[key] = expandPath(value)
}
}
return cfg, nil
}