From 23dd7b90162e02884baab1d1592e81c94eed8a5a Mon Sep 17 00:00:00 2001 From: Thomas Piccirello Date: Mon, 30 Dec 2019 22:33:49 -0800 Subject: [PATCH 1/2] Improve run support for arbitrary commands Commands like `doppler run "node && node"` or `doppler run -- node -v` were failing to execute. This change passes the user's command to a new shell to improve compatability. --- pkg/utils/util.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/utils/util.go b/pkg/utils/util.go index a312202b..2da0745a 100644 --- a/pkg/utils/util.go +++ b/pkg/utils/util.go @@ -21,6 +21,7 @@ import ( "path/filepath" "runtime" "strconv" + "strings" "time" "github.com/AlecAivazis/survey/v2" @@ -67,7 +68,12 @@ func Cwd() string { // RunCommand runs the specified command func RunCommand(command []string, env []string) (int, error) { - cmd := exec.Command(command[0], command[1:]...) + shell := [2]string{"sh", "-c"} + if IsWindows() { + shell = [2]string{"cmd", "/C"} + } + + cmd := exec.Command(shell[0], shell[1], strings.Join(command, " ")) cmd.Env = env cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout @@ -215,3 +221,7 @@ func HostArch() string { return arch } + +func IsWindows() bool { + return runtime.GOOS == "windows" +} From 1093a4b33d439bbc2f93786eea67889efaac6aaf Mon Sep 17 00:00:00 2001 From: Thomas Piccirello Date: Mon, 30 Dec 2019 22:34:26 -0800 Subject: [PATCH 2/2] Document required args better --- pkg/cmd/run.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go index d314ceb0..c8d9ed95 100644 --- a/pkg/cmd/run.go +++ b/pkg/cmd/run.go @@ -133,8 +133,8 @@ func init() { runCmd.Flags().StringP("config", "c", "", "enclave config (e.g. dev)") runCmd.Flags().String("fallback", "", "write secrets to this file after connecting to Doppler. secrets will be read from this file if future connection attempts are unsuccessful.") - runCmd.Flags().Bool("fallback-readonly", false, "do not update or modify the fallback file") - runCmd.Flags().Bool("fallback-only", false, "do not request secrets from Doppler. all secrets will be read directly from the fallback file") + runCmd.Flags().Bool("fallback-readonly", false, "do not update or modify the fallback file. [requires --fallback]") + runCmd.Flags().Bool("fallback-only", false, "do not request secrets from Doppler. all secrets will be read directly from the fallback file. [requires --fallback]") rootCmd.AddCommand(runCmd) }