diff options
author | Victor Häggqvist <[email protected]> | 2020-04-21 09:34:44 +0200 |
---|---|---|
committer | Victor Häggqvist <[email protected]> | 2020-04-21 09:34:44 +0200 |
commit | d21f39eeebd3586e7faf4d83c7a8e12b6e04c82e (patch) | |
tree | 1793d726cd50cb2d3a4311d8bb38fbf3fbdeda12 /goboom.go | |
parent | d0a84f15f765383e077fee487af61c0e2e6bdf6d (diff) |
replace ini
Diffstat (limited to '')
-rw-r--r-- | goboom.go | 31 |
1 files changed, 17 insertions, 14 deletions
@@ -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() |