make common config processing code

This commit is contained in:
Jeff Carr 2024-02-22 21:10:01 -06:00
parent 7cfdbf32af
commit 59ff2df1db
1 changed files with 1 additions and 44 deletions

View File

@ -3,35 +3,14 @@ package main
// this initializes the repos
import (
"io/ioutil"
"os"
"os/user"
"path/filepath"
"strings"
"go.wit.com/lib/gui/repostatus"
"go.wit.com/lib/gui/shell"
"go.wit.com/log"
)
func (r *repoWindow) initRepoList() {
usr, _ := user.Current()
repos := parsecfg("~/.config/autotypist")
for _, line := range repos {
log.Verbose("repo =", line)
path, mbranch, dbranch, ubranch := splitLine(line)
if mbranch == "" {
mbranch = "master"
}
if dbranch == "" {
dbranch = "devel"
}
if ubranch == "" {
ubranch = usr.Username
}
r.View.NewRepo(path)
}
r.View.InitRepoList("~/.config/autotypist")
if args.OnlyMe {
log.Info("not scanning everything")
@ -46,25 +25,3 @@ func (r *repoWindow) initRepoList() {
}
}
}
func parsecfg(f string) []string {
homeDir, _ := os.UserHomeDir()
cfgfile := filepath.Join(homeDir, f)
content, _ := ioutil.ReadFile(cfgfile)
out := string(content)
out = strings.TrimSpace(out)
lines := strings.Split(out, "\n")
return lines
}
// returns path, master branch name, devel branch name, user branch name
func splitLine(line string) (string, string, string, string) {
var path, master, devel, user string
parts := strings.Split(line, " ")
path, parts = shell.RemoveFirstElement(parts)
master, parts = shell.RemoveFirstElement(parts)
devel, parts = shell.RemoveFirstElement(parts)
user, parts = shell.RemoveFirstElement(parts)
// path, master, devel, user := strings.Split(line, " ")
return path, master, devel, user
}