package gitpb import ( "os" "path/filepath" "strings" "github.com/go-cmd/cmd" "go.wit.com/lib/gui/shell" "go.wit.com/log" ) // execute something with the working directory // set to the FullPath func (repo *Repo) Run(cmd []string) cmd.Status { result := shell.PathRun(repo.FullPath, cmd) output := strings.Join(result.Stdout, "\n") if result.Error != nil { log.Warn("cmd:", cmd) log.Warn("ouptput:", output) log.Warn("failed with error:", result.Error) } return result } func (repo *Repo) RunQuiet(cmd []string) cmd.Status { result := shell.PathRunQuiet(repo.FullPath, cmd) output := strings.Join(result.Stdout, "\n") if result.Error != nil { log.Warn("cmd:", cmd) log.Warn("ouptput:", output) log.Warn("failed with error:", result.Error) } return result } // for now, even check cmd.Exit func (repo *Repo) strictRun(cmd []string) (bool, error) { result := repo.RunQuiet(cmd) if result.Error != nil { log.Warn("go mod init failed err:", result.Error) return false, result.Error } if result.Exit != 0 { log.Warn("go mod init exit =", result.Exit) return false, result.Error } return true, nil } func (repo *Repo) Exists(filename string) bool { if repo == nil { log.Warn("repo == nil for Exists()") panic(-1) } testf := filepath.Join(repo.FullPath, filename) _, err := os.Stat(testf) if err != nil { return false } return true }