add RunVerbose() RunVerboseOnError()
This commit is contained in:
parent
0146183226
commit
364d666eb6
47
cmd.go
47
cmd.go
|
@ -2,6 +2,7 @@ package shell
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -241,3 +242,49 @@ func RemoveFirstElement(slice []string) (string, []string) {
|
||||||
}
|
}
|
||||||
return slice[0], slice[1:] // Return the slice without the first element
|
return slice[0], slice[1:] // Return the slice without the first element
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RunVerbose(cmd []string) (*cmd.Status, error) {
|
||||||
|
pwd, _ := os.Getwd()
|
||||||
|
log.Info("Running:", pwd, cmd)
|
||||||
|
r, err := RunStrict(cmd)
|
||||||
|
if err != nil {
|
||||||
|
log.Info("Error", cmd, err)
|
||||||
|
}
|
||||||
|
for _, line := range r.Stdout {
|
||||||
|
log.Info(line)
|
||||||
|
}
|
||||||
|
for _, line := range r.Stderr {
|
||||||
|
log.Info(line)
|
||||||
|
}
|
||||||
|
return r, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func RunVerboseOnError(cmd []string) (*cmd.Status, error) {
|
||||||
|
r, err := RunStrict(cmd)
|
||||||
|
if err == nil {
|
||||||
|
return r, err
|
||||||
|
}
|
||||||
|
pwd, _ := os.Getwd()
|
||||||
|
log.Info("Run Error:", pwd, cmd, err)
|
||||||
|
for _, line := range r.Stdout {
|
||||||
|
log.Info(line)
|
||||||
|
}
|
||||||
|
for _, line := range r.Stderr {
|
||||||
|
log.Info(line)
|
||||||
|
}
|
||||||
|
return r, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func RunStrict(cmd []string) (*cmd.Status, error) {
|
||||||
|
pwd, _ := os.Getwd()
|
||||||
|
result := PathRunQuiet(pwd, cmd)
|
||||||
|
if result.Error != nil {
|
||||||
|
log.Warn(pwd, cmd, "wow. golang is cool. an os.Error:", result.Error)
|
||||||
|
return &result, result.Error
|
||||||
|
}
|
||||||
|
if result.Exit != 0 {
|
||||||
|
// log.Warn(cmd, "failed with", result.Exit, repo.GetGoPath())
|
||||||
|
return &result, errors.New(fmt.Sprint(cmd, "failed with", result.Exit))
|
||||||
|
}
|
||||||
|
return &result, nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue