repolist/common.go

179 lines
3.3 KiB
Go

package repolist
import (
"go.wit.com/gui"
"go.wit.com/lib/gui/repostatus"
"go.wit.com/log"
)
func (r *RepoList) Hidden() bool {
return r.reposbox.Hidden()
}
func (r *RepoList) Show() {
r.reposbox.Show()
}
func (r *RepoList) Hide() {
r.reposbox.Hide()
}
func (r *RepoList) FindRepo(path string) *RepoRow {
repo, _ := me.allrepos[path]
return repo
}
func (r *RepoList) AllRepos() []*RepoRow {
var all []*RepoRow
for _, repo := range me.allrepos {
all = append(all, repo)
}
return all
}
// deprecate this
func AllRepos() []*RepoRow {
var all []*RepoRow
for _, repo := range me.allrepos {
all = append(all, repo)
}
return all
}
// a human readable state of the current repo
func (r *RepoRow) State() string {
return r.gitState.String()
}
func (r *RepoRow) Scan() int {
return r.NewScan()
}
// returns a name for human consuption only
// todo: implement nicknames
func (rs *RepoRow) Name() string {
if rs.Status.IsGoLang() {
return rs.Status.GoPath()
}
return rs.Status.Path()
}
func (r *RepoRow) Exists(s string) bool {
return false
}
func (r *RepoRow) GoPath() string {
return r.Status.GoPath()
}
func (r *RepoRow) CheckDirty() bool {
return r.Status.CheckDirty()
}
func (r *RepoRow) IsDirty() bool {
return r.Status.IsDirty()
}
func (r *RepoRow) ReadOnly() bool {
if r == nil {
log.Warn("ReadOnly() repo == nil")
return false
}
if r.Status == nil {
log.Warn("ReadOnly() repo.Status == nil")
return false
}
return r.Status.ReadOnly()
}
func (r *RepoRow) LastTag() string {
if r == nil {
log.Warn("LastTag() repo == nil")
return ""
}
return r.lastTag.String()
}
/*
// returns the state of the GO go.mod and go.sum files
// this is used to tell if they are valid and correctly reflect
// the versions of the other GUI packages
// at this point in time, there is _NO_ way to be check our
// be sure that anything will run with older versions
// because this are changing too often at this point
// TODO: revisit this in 2025 or 2026
func (r *RepoRow) GoState() string {
if r == nil {
log.Info("GoState() r == nil")
return "goState == nil"
}
if r.goState == nil {
log.Info("GoState() r.goState == nil")
return "goState == nil"
}
return r.goState.String()
}
func (r *RepoRow) SetGoState(s string) {
if r == nil {
log.Info("SetGoState() r == nil")
return
}
if r.goState == nil {
log.Info("goState == nil")
return
}
r.goState.SetText(s)
}
*/
func (r *RepoRow) IsPerfect() bool {
if r.gitState.String() == "PERFECT" {
return true
}
if r.gitState.String() == "unchanged" {
return true
}
return false
}
func (r *RepoRow) RunCmd(cmd []string) (error, string) {
return r.Status.RunCmd(cmd)
}
func (r *RepoRow) AllTags() []*repostatus.Tag {
return r.Status.Tags.ListAll()
}
func (r *RepoRow) TagsBox() *repostatus.GitTagBox {
return r.Status.Tags
}
// todo, fix bool return for deletetag()
func (r *RepoRow) DeleteTag(t *repostatus.Tag) bool {
r.Status.DeleteTag(t)
return true
}
func (rl *RepoList) MirrorShownCount() *gui.Node {
return gui.RawMirror(rl.shownCount)
}
func (rl *RepoList) MirrorScanDuration() *gui.Node {
return gui.RawMirror(rl.duration)
}
func (rl *RepoList) Total() int {
return len(me.allrepos)
}
func (rl *RepoList) TotalGo() int {
var count int
for _, repo := range me.allrepos {
if repo.Status.IsGoLang() {
count += 1
}
}
return count
}