repostatus/common.go

137 lines
2.6 KiB
Go
Raw Normal View History

2024-01-09 15:34:53 -06:00
package repostatus
import (
"strings"
2024-01-09 15:34:53 -06:00
"go.wit.com/log"
// "go.wit.com/gui/gui"
2024-01-09 15:34:53 -06:00
)
// reports externally if something has changed
// since the last time it was asked about it
func (rs *RepoStatus) Changed() bool {
if !rs.Ready() {
return false
}
return rs.changed
2024-01-09 15:34:53 -06:00
}
// deprecate this. returns the gopath right now
func (rs *RepoStatus) String() string {
2024-02-16 01:22:37 -06:00
// log.Warn("RepoStatus.String() is to be deprecated")
return rs.path.String()
}
// returns the go path for the repo. "go.wit.com/apps/autotypist"
func (rs *RepoStatus) GoName() string {
return rs.goSrcPath.String()
}
// returns the filesystem path to the repo
func (rs *RepoStatus) Path() string {
return rs.realPath.String()
}
/*
func (rs *RepoStatus) GetPath() string {
return rs.path.String()
}
*/
/*
func (rs *RepoStatus) Draw() {
if !rs.Ready() {
return
}
log.Log(CHANGE, "Draw() window ready =", rs.ready)
rs.window.TestDraw()
2024-01-09 15:34:53 -06:00
}
*/
2024-01-13 20:30:33 -06:00
func (rs *RepoStatus) Show() {
if !rs.Ready() {
return
}
log.Log(CHANGE, "Show() window ready =", rs.ready)
rs.window.Show()
2024-01-09 15:34:53 -06:00
}
func (rs *RepoStatus) Hide() {
if !rs.Ready() {
return
}
log.Log(CHANGE, "Hide() window ready =", rs.ready)
rs.window.Hide()
2024-01-09 15:34:53 -06:00
}
func (rs *RepoStatus) Toggle() {
if !rs.Ready() {
return
}
log.Log(CHANGE, "Toggle() window ready =", rs.ready)
if rs.window.Hidden() {
rs.Show()
2024-01-09 15:34:53 -06:00
} else {
rs.Hide()
2024-01-09 15:34:53 -06:00
}
}
func (rs *RepoStatus) Ready() bool {
if rs == nil {
return false
}
if rs.window == nil {
return false
}
return rs.ready
2024-01-09 15:34:53 -06:00
}
/*
func (rs *RepoStatus) Initialized() bool {
2024-01-09 15:34:53 -06:00
log.Log(CHANGE, "checking Initialized()")
if rs == nil {return false}
if rs.parent == nil {return false}
2024-01-09 15:34:53 -06:00
return true
}
*/
func (rs *RepoStatus) RepoType() string {
err, output := rs.RunCmd([]string{"go", "list", "-f", "'{{if eq .Name \"main\"}}binary{{else}}library{{end}}'"})
if err == nil {
output = strings.Trim(output, "'")
2024-02-16 01:22:37 -06:00
// log.Info("go package is:", output)
return output
}
2024-02-16 01:22:37 -06:00
// log.Info("package is: unknown", err)
return ""
}
2024-02-12 21:50:54 -06:00
func (rs *RepoStatus) BinaryName() string {
// get the package name from the repo name
path := rs.String()
parts := strings.Split(path, "/")
name := parts[len(parts)-1]
return name
}
func (rs *RepoStatus) Build() bool {
name := rs.BinaryName()
// removes the binary if it already exists
rs.RunCmd([]string{"rm", "-f", name})
if rs.Exists(name) {
log.Warn("file could not be removed filename =", name)
return false
}
log.Info("need to build here", rs.String())
// rs.RunCmd([]string{"go", "build", "-v", "-x"})
rs.XtermBash([]string{"go", "build", "-v", "-x"})
2024-02-12 21:50:54 -06:00
if rs.Exists(name) {
log.Warn("build worked", name)
return true
}
log.Warn("build failed", name)
return false
}