1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Add cfg/ as a top-level package concept

This commit is contained in:
Chris Cummer 2018-06-09 03:58:45 -07:00
parent 00c07a9421
commit d2dfcd8978
3 changed files with 13 additions and 10 deletions

View File

@ -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
}

View File

@ -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)

7
wtf.go
View File

@ -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")))