From 2975833e643f7cfa8d62e2c59289735ec113d247 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 22 Feb 2024 21:12:35 -0600 Subject: new Repo rewrite --- configfile.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 configfile.go (limited to 'configfile.go') diff --git a/configfile.go b/configfile.go new file mode 100644 index 0000000..a339d70 --- /dev/null +++ b/configfile.go @@ -0,0 +1,36 @@ +package repolist + +import ( + "io/ioutil" + "os" + "path/filepath" + "strings" + + "go.wit.com/log" +) + +func (v *RepoList) InitRepoList(cfgfile string) { + lines := parsecfg(cfgfile) + for _, line := range lines { + log.Verbose("repo =", line) + line = strings.TrimSpace(line) + if strings.HasPrefix(line, "#") { + continue + } + parts := strings.Split(line, " ") + if len(parts) > 0 { + path := parts[0] + v.NewRepo(path) + } + } +} + +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 +} -- cgit v1.2.3