gitpb/shell.go

82 lines
1.7 KiB
Go
Raw Normal View History

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
}
2024-11-28 21:04:10 -06:00
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
}
2024-12-01 22:23:38 -06:00
func (repo *Repo) RunRealtime(cmd []string) cmd.Status {
return shell.PathRunRealtime(repo.GetFullPath(), cmd)
}
// for now, even check cmd.Exit
func (repo *Repo) strictRun(cmd []string) (bool, error) {
2024-11-30 02:03:32 -06:00
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()")
2024-12-01 22:37:11 -06:00
return false
}
testf := filepath.Join(repo.FullPath, filename)
_, err := os.Stat(testf)
if err != nil {
return false
}
return true
}
2024-12-01 11:44:20 -06:00
2024-12-01 16:04:07 -06:00
func (repo *Repo) IsValid() bool {
if !repo.IsDirectory() {
return false
}
return true
}
2024-12-01 11:44:20 -06:00
func (repo *Repo) IsDirectory() bool {
info, err := os.Stat(repo.FullPath)
if err != nil {
return false
}
return info.IsDir()
}