Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve run support for arbitrary commands #52

Merged
merged 2 commits into from
Dec 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
12 changes: 11 additions & 1 deletion pkg/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"path/filepath"
"runtime"
"strconv"
"strings"
"time"

"github.com/AlecAivazis/survey/v2"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -215,3 +221,7 @@ func HostArch() string {

return arch
}

func IsWindows() bool {
return runtime.GOOS == "windows"
}