diff options
| author | Jeff Carr <[email protected]> | 2024-11-27 21:40:06 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-11-27 21:40:06 -0600 |
| commit | ed3eacfe75e479e8c36cf7ba82a431c567f83602 (patch) | |
| tree | 450d0cc89758efd161c426868d6cbc6e4ef470d0 /shell.go | |
| parent | 8b987962ea21a827d50e7f7430ab58b47274ad0e (diff) | |
first attempt that seems to kinda work on New()
Diffstat (limited to 'shell.go')
| -rw-r--r-- | shell.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/shell.go b/shell.go new file mode 100644 index 0000000..de82f84 --- /dev/null +++ b/shell.go @@ -0,0 +1,51 @@ +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 +} + +// for now, even check cmd.Exit +func (repo *Repo) strictRun(cmd []string) (bool, error) { + result := repo.Run(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 +} |
