Skip to content

Commit

Permalink
input and config enhancements (#40)
Browse files Browse the repository at this point in the history
* allowing tilde in working dir inputs

* ignoring case in y/n prompts

* user env vars are now prepended to shell vars
  • Loading branch information
sha1n authored May 22, 2021
1 parent 8aff3ec commit 58ab21c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions internal/cli/stdin.go → internal/cli/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func QuestionYN(prompt string) bool {
for {
displayPrompt()
str, _ = reader.ReadString('\n')
str = strings.TrimSpace(str)
str = strings.TrimSpace(strings.ToLower(str))
if str == "y" {
return true
} else if str == "n" || str == "" {
Expand All @@ -67,7 +67,7 @@ func RequestExistingDirectory(prompt string, required bool) string {
if path == "" {
return true
}
_, err := os.Stat(path)
_, err := os.Stat(expandPath(path))
exists := !os.IsNotExist(err)
if !exists {
_, _ = printfRed("the directory '%s' does not exist\r\n", path)
Expand Down
1 change: 1 addition & 0 deletions pkg/command_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func (ce *commandExecutor) configureCommand(cmd *api.CommandSpec, execCmd *exec.
cmdEnv := toEnvVarsArray(env)
log.Debugf("Populating command environment variables '%v'", cmdEnv)
execCmd.Env = append(execCmd.Env, cmdEnv...)
execCmd.Env = append(execCmd.Env, os.Environ()...)
}

if ce.pipeStdout {
Expand Down
8 changes: 4 additions & 4 deletions pkg/command_exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestConfigureCommandWithEmptyWorkingDir(t *testing.T) {
execCmd := configureCommand(aCommandSpec(cmd, ""), defaultWorkingDir, env)

assert.Equal(t, defaultWorkingDir, execCmd.Dir)
assert.Equal(t, []string(nil), execCmd.Env)
assert.Equal(t, os.Environ(), execCmd.Env)
assert.Equal(t, cmd, execCmd.Args)
}

Expand All @@ -32,7 +32,7 @@ func TestConfigureCommandWithTildeDefaultWorkingDir(t *testing.T) {
execCmd := configureCommand(aCommandSpec(cmd, ""), defaultWorkingDir, env)

assert.Equal(t, userHomeDir(), execCmd.Dir)
assert.Equal(t, []string(nil), execCmd.Env)
assert.Equal(t, os.Environ(), execCmd.Env)
assert.Equal(t, cmd, execCmd.Args)
}

Expand All @@ -44,7 +44,7 @@ func TestConfigureCommandWithTildeLocalWorkingDir(t *testing.T) {
execCmd := configureCommand(aCommandSpec(cmd, "~"), defaultWorkingDir, env)

assert.Equal(t, userHomeDir(), execCmd.Dir)
assert.Equal(t, []string(nil), execCmd.Env)
assert.Equal(t, os.Environ(), execCmd.Env)
assert.Equal(t, cmd, execCmd.Args)
}

Expand Down Expand Up @@ -78,7 +78,7 @@ func aCustomEnv() map[string]string {
}

func expectedEnvFor(e map[string]string) []string {
return toEnvVarsArray(e)
return append(toEnvVarsArray(e), os.Environ()...) // user vars are expected to be first
}

func userHomeDir() string {
Expand Down

0 comments on commit 58ab21c

Please sign in to comment.