From d21f39eeebd3586e7faf4d83c7a8e12b6e04c82e Mon Sep 17 00:00:00 2001 From: Victor Häggqvist Date: Tue, 21 Apr 2020 09:34:44 +0200 Subject: replace ini --- goboom.go | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'goboom.go') diff --git a/goboom.go b/goboom.go index 0c8dad8..5ccfd0b 100644 --- a/goboom.go +++ b/goboom.go @@ -7,12 +7,13 @@ import ( "os" "os/user" "path/filepath" + "runtime" "sort" "strings" - "github.com/go-ini/ini" "github.com/gocarina/gocsv" - flag "github.com/victorhaggqvist/pflag" + flag "github.com/spf13/pflag" + "gopkg.in/yaml.v2" ) var version = "0.0.0" // injected at build time @@ -23,8 +24,8 @@ type Runnable struct { } type Config struct { - DmenuParams string - Ignore []string `delim:","` + DmenuParams string `yaml:"dmenu_params"` + Ignore []string `yaml:"ignore,flow"` } type CmdList []*Runnable @@ -127,7 +128,7 @@ func rankPath(pathItems []string) CmdList { func loadIni() { usr, _ := user.Current() configPath := filepath.Join(usr.HomeDir, ".goboom") - iniFile := filepath.Join(configPath, "config.ini") + iniFile := filepath.Join(configPath, "config.yaml") dbFilePath = filepath.Join(configPath, "rankdb.csv") if _, err := os.Stat(configPath); err != nil { @@ -141,18 +142,21 @@ func loadIni() { DmenuParams: "-b -i -nb black -nf orange -sb black -p \">\"", Ignore: []string{"X", "su"}, } - if _, err := os.Stat(iniFile); err != nil { - newCfg := ini.Empty() - newCfg.NameMapper = ini.TitleUnderscore - err := ini.ReflectFrom(newCfg, &config) + if _, err := os.Stat(iniFile); err != nil { + buff, err := yaml.Marshal(config) if err != nil { panic(err) } - - newCfg.SaveTo(iniFile) + if err := ioutil.WriteFile(iniFile, buff, 0644); err != nil { + panic(err) + } } else { - if err := ini.MapToWithMapper(&config, ini.TitleUnderscore, iniFile); err != nil { + buff, err := ioutil.ReadFile(iniFile) + if err != nil { + panic(err) + } + if err := yaml.Unmarshal(buff, &config); err != nil { panic(err) } } @@ -226,9 +230,8 @@ func main() { flag.BoolVar(&postPhase, "post", false, "Update ranking DB") flag.BoolVar(&stats, "stats", false, "View DB stats") flag.BoolVar(&gc, "gc", false, "Run garbage collection of the DB") - flag.Version = version flag.Usage = func() { - flag.PrintVersion() + fmt.Println(version + " " + runtime.Version()) fmt.Print("\nTo actually use goboom execute goboom_run\n\n") fmt.Println("Options: ") flag.PrintDefaults() -- cgit v1.2.3