From 58ab21c172996012e8a86e78ed53c738b48c4e35 Mon Sep 17 00:00:00 2001 From: Shai Nagar Date: Sat, 22 May 2021 23:34:42 +0300 Subject: [PATCH] input and config enhancements (#40) * allowing tilde in working dir inputs * ignoring case in y/n prompts * user env vars are now prepended to shell vars --- internal/cli/{stdin.go => input.go} | 4 ++-- pkg/command_exec.go | 1 + pkg/command_exec_test.go | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-) rename internal/cli/{stdin.go => input.go} (96%) diff --git a/internal/cli/stdin.go b/internal/cli/input.go similarity index 96% rename from internal/cli/stdin.go rename to internal/cli/input.go index 38b3ef8..f04f334 100644 --- a/internal/cli/stdin.go +++ b/internal/cli/input.go @@ -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 == "" { @@ -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) diff --git a/pkg/command_exec.go b/pkg/command_exec.go index e04954f..a90de56 100644 --- a/pkg/command_exec.go +++ b/pkg/command_exec.go @@ -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 { diff --git a/pkg/command_exec_test.go b/pkg/command_exec_test.go index 8f45d3e..f5992c4 100644 --- a/pkg/command_exec_test.go +++ b/pkg/command_exec_test.go @@ -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) } @@ -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) } @@ -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) } @@ -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 {