runLocal runs a command on the local machine.
(ctx context.Context, stdin io.Reader, name string, args ...string)
| 1204 | |
| 1205 | // runLocal runs a command on the local machine. |
| 1206 | func runLocal(ctx context.Context, stdin io.Reader, name string, args ...string) ([]byte, error) { |
| 1207 | cmd := exec.CommandContext(ctx, name, args...) |
| 1208 | cmd.Stdin = stdin |
| 1209 | |
| 1210 | out, err := cmd.Output() |
| 1211 | if err != nil { |
| 1212 | var stderr []byte |
| 1213 | if exitErr := new(exec.ExitError); errors.As(err, &exitErr) { |
| 1214 | stderr = exitErr.Stderr |
| 1215 | } |
| 1216 | |
| 1217 | return out, xerrors.Errorf( |
| 1218 | "`%s %s` failed: stderr: %s\n\nstdout: %s\n\n%w", |
| 1219 | name, |
| 1220 | strings.Join(args, " "), |
| 1221 | bytes.TrimSpace(stderr), |
| 1222 | bytes.TrimSpace(out), |
| 1223 | err, |
| 1224 | ) |
| 1225 | } |
| 1226 | |
| 1227 | return out, nil |
| 1228 | } |
| 1229 | |
| 1230 | // runRemoteSSH runs a command on a remote machine/workspace via SSH. |
| 1231 | func runRemoteSSH(sshClient *gossh.Client, stdin io.Reader, cmd string) ([]byte, error) { |
no test coverage detected