(command api.CLIStepCLICommand, variables map[string]string)
| 12 | ) |
| 13 | |
| 14 | func runCLICommand(command api.CLIStepCLICommand, variables map[string]string) (result api.CLICommandResult) { |
| 15 | finalCommand := InterpolateVariables(command.Command, variables) |
| 16 | result.FinalCommand = finalCommand |
| 17 | result.Command = command |
| 18 | |
| 19 | var cmd *exec.Cmd |
| 20 | |
| 21 | if runtime.GOOS == "windows" { |
| 22 | cmd = exec.Command("powershell", "-Command", finalCommand) |
| 23 | } else { |
| 24 | cmd = exec.Command("sh", "-c", finalCommand) |
| 25 | } |
| 26 | |
| 27 | cmd.Env = append(os.Environ(), "LANG=en_US.UTF-8") |
| 28 | b, err := cmd.CombinedOutput() |
| 29 | if ee, ok := err.(*exec.ExitError); ok { |
| 30 | result.ExitCode = ee.ExitCode() |
| 31 | } else if err != nil { |
| 32 | result.ExitCode = -2 |
| 33 | } |
| 34 | result.Stdout = strings.TrimRight(string(b), " \n\t\r") |
| 35 | if command.StdoutFilterTmdl != nil { |
| 36 | result.Stdout = ExtractTmdlBlock(result.Stdout, *command.StdoutFilterTmdl) |
| 37 | } |
| 38 | result.Variables = maps.Clone(variables) |
| 39 | return result |
| 40 | } |
| 41 | |
| 42 | func prettyPrintCLICommand(test api.CLICommandTest, variables map[string]string) string { |
| 43 | if test.ExitCode != nil { |
no test coverage detected