repolist/common.go

159 lines
2.9 KiB
Go
Raw Normal View History

2024-02-17 08:39:55 -06:00
package repolist
import (
2024-02-19 19:43:21 -06:00
"go.wit.com/gui"
2024-02-19 21:11:32 -06:00
"go.wit.com/lib/gui/repostatus"
2024-02-18 17:56:25 -06:00
"go.wit.com/log"
2024-02-17 08:39:55 -06:00
)
func (r *RepoList) Hidden() bool {
2024-02-17 14:22:24 -06:00
return r.reposbox.Hidden()
2024-02-17 08:39:55 -06:00
}
func (r *RepoList) Show() {
2024-02-17 14:22:24 -06:00
r.reposbox.Show()
2024-02-17 08:39:55 -06:00
}
func (r *RepoList) Hide() {
2024-02-17 14:22:24 -06:00
r.reposbox.Hide()
2024-02-17 08:39:55 -06:00
}
2024-02-18 15:09:35 -06:00
func (r *RepoList) FindRepo(path string) *Repo {
repo, _ := me.allrepos[path]
return repo
}
2024-02-17 08:39:55 -06:00
func (r *RepoList) AllRepos() []*Repo {
var all []*Repo
for _, repo := range me.allrepos {
all = append(all, repo)
}
return all
}
// deprecate this
func AllRepos() []*Repo {
var all []*Repo
for _, repo := range me.allrepos {
all = append(all, repo)
}
return all
}
2024-02-17 15:48:56 -06:00
// a human readable state of the current repo
func (r *Repo) State() string {
return r.gitState.String()
2024-02-17 14:22:24 -06:00
}
2024-02-17 08:39:55 -06:00
func (r *Repo) Scan() bool {
2024-02-17 14:22:24 -06:00
return r.NewScan()
2024-02-17 08:39:55 -06:00
}
2024-02-17 15:48:56 -06:00
// returns a name for human consuption only
// todo: implement nicknames
func (rs *Repo) Name() string {
if rs.Status.IsGoLang() {
return rs.Status.GoPath()
}
return rs.Status.Path()
2024-02-17 08:39:55 -06:00
}
2024-02-17 15:48:56 -06:00
func (r *Repo) Exists(s string) bool {
return false
2024-02-17 08:39:55 -06:00
}
2024-02-17 15:48:56 -06:00
func (r *Repo) GoPath() string {
return r.Status.GoPath()
2024-02-17 08:39:55 -06:00
}
func (r *Repo) CheckDirty() bool {
2024-02-17 15:48:56 -06:00
return r.Status.CheckDirty()
2024-02-17 08:39:55 -06:00
}
func (r *Repo) IsDirty() bool {
2024-02-17 15:48:56 -06:00
return r.Status.IsDirty()
2024-02-17 08:39:55 -06:00
}
func (r *Repo) ReadOnly() bool {
2024-02-19 19:43:21 -06:00
if r == nil {
log.Warn("ReadOnly() repo == nil")
return false
}
if r.Status == nil {
log.Warn("ReadOnly() repo.Status == nil")
return false
}
2024-02-17 15:48:56 -06:00
return r.Status.ReadOnly()
2024-02-17 08:39:55 -06:00
}
2024-02-18 15:09:35 -06:00
func (r *Repo) LastTag() string {
2024-02-19 19:43:21 -06:00
if r == nil {
log.Warn("LastTag() repo == nil")
return ""
}
return r.lastTag.String()
2024-02-18 15:09:35 -06:00
}
// 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 *Repo) GoState() string {
2024-02-18 17:56:25 -06:00
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()
2024-02-18 15:09:35 -06:00
}
func (r *Repo) SetGoState(s string) {
2024-02-18 17:56:25 -06:00
if r == nil {
log.Info("SetGoState() r == nil")
return
}
if r.goState == nil {
log.Info("goState == nil")
return
}
r.goState.SetText(s)
2024-02-18 15:09:35 -06:00
}
2024-02-17 08:39:55 -06:00
func (r *Repo) IsPerfect() bool {
if r.gitState.String() == "PERFECT" {
2024-02-17 08:39:55 -06:00
return true
}
if r.gitState.String() == "unchanged" {
2024-02-17 14:22:24 -06:00
return true
}
2024-02-17 08:39:55 -06:00
return false
}
func (r *Repo) RunCmd(cmd []string) (error, string) {
2024-02-17 15:48:56 -06:00
return r.Status.RunCmd(cmd)
2024-02-17 08:39:55 -06:00
}
func (r *Repo) AllTags() []*repostatus.Tag {
2024-02-17 15:48:56 -06:00
return r.Status.Tags.ListAll()
2024-02-17 08:39:55 -06:00
}
func (r *Repo) TagsBox() *repostatus.GitTagBox {
2024-02-17 15:48:56 -06:00
return r.Status.Tags
2024-02-17 08:39:55 -06:00
}
// todo, fix bool return for deletetag()
func (r *Repo) DeleteTag(t *repostatus.Tag) bool {
2024-02-17 15:48:56 -06:00
r.Status.DeleteTag(t)
2024-02-17 08:39:55 -06:00
return true
}
2024-02-19 19:43:21 -06:00
func (rl *RepoList) MirrorShownCount() *gui.Node {
return gui.RawMirror(rl.shownCount)
}