From d2dfcd8978a4ae886c3dda17227dbdd1f7e687f2 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Sat, 9 Jun 2018 03:58:45 -0700 Subject: [PATCH] Add cfg/ as a top-level package concept --- {wtf => cfg}/config_files.go | 9 +++++---- todo/widget.go | 7 ++++--- wtf.go | 7 ++++--- 3 files changed, 13 insertions(+), 10 deletions(-) rename {wtf => cfg}/config_files.go (94%) diff --git a/wtf/config_files.go b/cfg/config_files.go similarity index 94% rename from wtf/config_files.go rename to cfg/config_files.go index ff57654d..85e848e8 100644 --- a/wtf/config_files.go +++ b/cfg/config_files.go @@ -1,4 +1,4 @@ -package wtf +package cfg import ( "fmt" @@ -6,10 +6,11 @@ import ( "os" "github.com/olebedev/config" + "github.com/senorprogrammer/wtf/wtf" ) func ConfigDir() (string, error) { - configDir, err := ExpandHomeDir("~/.wtf/") + configDir, err := wtf.ExpandHomeDir("~/.wtf/") if err != nil { return "", err } @@ -59,7 +60,7 @@ func CreateFile(fileName string) (string, error) { // LoadConfigFile loads the config.yml file to configure the app func LoadConfigFile(filePath string) *config.Config { - absPath, _ := ExpandHomeDir(filePath) + absPath, _ := wtf.ExpandHomeDir(filePath) cfg, err := config.ParseYamlFile(absPath) if err != nil { @@ -79,7 +80,7 @@ func ReadConfigFile(fileName string) (string, error) { filePath := fmt.Sprintf("%s/%s", configDir, fileName) - fileData, err := ReadFileBytes(filePath) + fileData, err := wtf.ReadFileBytes(filePath) if err != nil { return "", err } diff --git a/todo/widget.go b/todo/widget.go index 00dcb984..f529f53e 100644 --- a/todo/widget.go +++ b/todo/widget.go @@ -7,6 +7,7 @@ import ( "github.com/gdamore/tcell" "github.com/olebedev/config" "github.com/rivo/tview" + "github.com/senorprogrammer/wtf/cfg" "github.com/senorprogrammer/wtf/wtf" "gopkg.in/yaml.v2" ) @@ -95,7 +96,7 @@ func (widget *Widget) editItem() { } func (widget *Widget) init() { - _, err := wtf.CreateFile(widget.filePath) + _, err := cfg.CreateFile(widget.filePath) if err != nil { panic(err) } @@ -177,7 +178,7 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey { // Loads the todo list from Yaml file func (widget *Widget) load() { - confDir, _ := wtf.ConfigDir() + confDir, _ := cfg.ConfigDir() filePath := fmt.Sprintf("%s/%s", confDir, widget.filePath) fileData, _ := wtf.ReadFileBytes(filePath) @@ -203,7 +204,7 @@ func (widget *Widget) newItem() { // persist writes the todo list to Yaml file func (widget *Widget) persist() { - confDir, _ := wtf.ConfigDir() + confDir, _ := cfg.ConfigDir() filePath := fmt.Sprintf("%s/%s", confDir, widget.filePath) fileData, _ := yaml.Marshal(&widget.list) diff --git a/wtf.go b/wtf.go index 954d3871..2c27fb13 100644 --- a/wtf.go +++ b/wtf.go @@ -12,6 +12,7 @@ import ( "github.com/rivo/tview" "github.com/senorprogrammer/wtf/bamboohr" "github.com/senorprogrammer/wtf/bargraph" + "github.com/senorprogrammer/wtf/cfg" "github.com/senorprogrammer/wtf/clocks" "github.com/senorprogrammer/wtf/cmdrunner" "github.com/senorprogrammer/wtf/cryptoexchanges/bittrex" @@ -260,7 +261,7 @@ func makeWidgets(app *tview.Application, pages *tview.Pages) { } func loadConfig(configFlag string) { - Config = wtf.LoadConfigFile(configFlag) + Config = cfg.LoadConfigFile(configFlag) } func main() { @@ -277,8 +278,8 @@ func main() { // Responsible for creating the configuration directory and default // configuration file if they don't already exist - wtf.CreateConfigDir() - wtf.WriteConfigFile() + cfg.CreateConfigDir() + cfg.WriteConfigFile() loadConfig(cmdFlags.Config) os.Setenv("TERM", Config.UString("wtf.term", os.Getenv("TERM")))