github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/internal/testhelpers/e2e/shell.go (about) 1 package e2e 2 3 import ( 4 "strings" 5 6 "github.com/ActiveState/cli/internal/osutils" 7 ) 8 9 type Shell string 10 11 const ( 12 Bash Shell = "bash" 13 Zsh = "zsh" 14 Tcsh = "tcsh" 15 Fish = "fish" 16 Cmd = "cmd.exe" 17 ) 18 19 // QuoteCommand constructs and returns a command line string from the given list of arguments. 20 // The returned string can be passed to the given shell for evaluation. 21 func QuoteCommand(shell Shell, args ...string) string { 22 escaper := osutils.NewBashEscaper() 23 if shell == Cmd { 24 escaper = osutils.NewCmdEscaper() 25 } 26 quotedArgs := make([]string, len(args)) 27 for i, arg := range args { 28 quotedArgs[i] = escaper.Quote(arg) 29 } 30 return strings.Join(quotedArgs, " ") 31 }