@@ -2,12 +2,28 @@ package command
22
33import (
44 "errors"
5+ "fmt"
56 "os"
7+ "os/exec"
68 "strings"
79
810 "github.com/bitrise-io/go-utils/pathutil"
911)
1012
13+ func runCommand (name string , args ... string ) error {
14+ cmd := exec .Command (name , args ... )
15+ if out , err := cmd .CombinedOutput (); err != nil {
16+ printableCmd := PrintableCommandArgs (false , append ([]string {name }, args ... ))
17+
18+ var exitErr * exec.ExitError
19+ if errors .As (err , & exitErr ) {
20+ return fmt .Errorf ("command failed with exit status %d (%s): %w" , exitErr .ExitCode (), printableCmd , errors .New (string (out )))
21+ }
22+ return fmt .Errorf ("executing command failed (%s): %w" , printableCmd , err )
23+ }
24+ return nil
25+ }
26+
1127// CopyFile ...
1228func CopyFile (src , dst string ) error {
1329 // replace with a pure Go implementation?
@@ -17,10 +33,10 @@ func CopyFile(src, dst string) error {
1733 return err
1834 }
1935 if isDir {
20- return errors .New ("Source is a directory: " + src )
36+ return errors .New ("source is a directory: " + src )
2137 }
2238 args := []string {src , dst }
23- return RunCommand ("rsync" , args ... )
39+ return runCommand ("rsync" , args ... )
2440}
2541
2642// CopyDir ...
@@ -29,7 +45,7 @@ func CopyDir(src, dst string, isOnlyContent bool) error {
2945 src = src + "/"
3046 }
3147 args := []string {"-ar" , src , dst }
32- return RunCommand ("rsync" , args ... )
48+ return runCommand ("rsync" , args ... )
3349}
3450
3551// RemoveDir ...
0 commit comments