From 59ff2df1dbe17bcfe6cce0bf0f6b517d857fb439 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 22 Feb 2024 21:10:01 -0600 Subject: [PATCH] make common config processing code --- initRepoList.go | 45 +-------------------------------------------- 1 file changed, 1 insertion(+), 44 deletions(-) diff --git a/initRepoList.go b/initRepoList.go index 3b47ac8..0a3b24c 100644 --- a/initRepoList.go +++ b/initRepoList.go @@ -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 -}