(cmd *Cmd)
| 90 | } |
| 91 | |
| 92 | func Output(cmd *Cmd) (string, error) { |
| 93 | out, err := cmd.Output() |
| 94 | |
| 95 | if exitError, ok := err.(*exec.ExitError); ok { |
| 96 | errorOutput := strings.TrimSpace(string(exitError.Stderr)) |
| 97 | if errorOutput == "" { |
| 98 | // some commands might write nothing to stderr but something to stdout in error-conditions, in which case, we'll use that |
| 99 | // in the error string |
| 100 | errorOutput = strings.TrimSpace(string(out)) |
| 101 | } |
| 102 | |
| 103 | ran := cmd.Path |
| 104 | if len(cmd.Args) > 1 { |
| 105 | ran = fmt.Sprintf("%s %s", cmd.Path, quotedArgs(cmd.Args[1:])) |
| 106 | } |
| 107 | formattedErr := errors.New(tr.Tr.Get("error running %s: '%s' '%s'", ran, errorOutput, strings.TrimSpace(exitError.Error()))) |
| 108 | |
| 109 | // return "" as output in error case, for callers that don't care about errors but rely on "" returned, in-case stdout != "" |
| 110 | return "", formattedErr |
| 111 | } |
| 112 | |
| 113 | return strings.Trim(string(out), " \n"), err |
| 114 | } |
| 115 | |
| 116 | var shellWordRe = regexp.MustCompile(`\A[A-Za-z0-9_@/.-]+\z`) |
| 117 |
no test coverage detected