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:
parent
00c07a9421
commit
d2dfcd8978
@ -1,4 +1,4 @@
|
|||||||
package wtf
|
package cfg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -6,10 +6,11 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/olebedev/config"
|
"github.com/olebedev/config"
|
||||||
|
"github.com/senorprogrammer/wtf/wtf"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ConfigDir() (string, error) {
|
func ConfigDir() (string, error) {
|
||||||
configDir, err := ExpandHomeDir("~/.wtf/")
|
configDir, err := wtf.ExpandHomeDir("~/.wtf/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@ -59,7 +60,7 @@ func CreateFile(fileName string) (string, error) {
|
|||||||
|
|
||||||
// LoadConfigFile loads the config.yml file to configure the app
|
// LoadConfigFile loads the config.yml file to configure the app
|
||||||
func LoadConfigFile(filePath string) *config.Config {
|
func LoadConfigFile(filePath string) *config.Config {
|
||||||
absPath, _ := ExpandHomeDir(filePath)
|
absPath, _ := wtf.ExpandHomeDir(filePath)
|
||||||
|
|
||||||
cfg, err := config.ParseYamlFile(absPath)
|
cfg, err := config.ParseYamlFile(absPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -79,7 +80,7 @@ func ReadConfigFile(fileName string) (string, error) {
|
|||||||
|
|
||||||
filePath := fmt.Sprintf("%s/%s", configDir, fileName)
|
filePath := fmt.Sprintf("%s/%s", configDir, fileName)
|
||||||
|
|
||||||
fileData, err := ReadFileBytes(filePath)
|
fileData, err := wtf.ReadFileBytes(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
@ -7,6 +7,7 @@ import (
|
|||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
"github.com/olebedev/config"
|
"github.com/olebedev/config"
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
|
"github.com/senorprogrammer/wtf/cfg"
|
||||||
"github.com/senorprogrammer/wtf/wtf"
|
"github.com/senorprogrammer/wtf/wtf"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
@ -95,7 +96,7 @@ func (widget *Widget) editItem() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) init() {
|
func (widget *Widget) init() {
|
||||||
_, err := wtf.CreateFile(widget.filePath)
|
_, err := cfg.CreateFile(widget.filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -177,7 +178,7 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
|||||||
|
|
||||||
// Loads the todo list from Yaml file
|
// Loads the todo list from Yaml file
|
||||||
func (widget *Widget) load() {
|
func (widget *Widget) load() {
|
||||||
confDir, _ := wtf.ConfigDir()
|
confDir, _ := cfg.ConfigDir()
|
||||||
filePath := fmt.Sprintf("%s/%s", confDir, widget.filePath)
|
filePath := fmt.Sprintf("%s/%s", confDir, widget.filePath)
|
||||||
|
|
||||||
fileData, _ := wtf.ReadFileBytes(filePath)
|
fileData, _ := wtf.ReadFileBytes(filePath)
|
||||||
@ -203,7 +204,7 @@ func (widget *Widget) newItem() {
|
|||||||
|
|
||||||
// persist writes the todo list to Yaml file
|
// persist writes the todo list to Yaml file
|
||||||
func (widget *Widget) persist() {
|
func (widget *Widget) persist() {
|
||||||
confDir, _ := wtf.ConfigDir()
|
confDir, _ := cfg.ConfigDir()
|
||||||
filePath := fmt.Sprintf("%s/%s", confDir, widget.filePath)
|
filePath := fmt.Sprintf("%s/%s", confDir, widget.filePath)
|
||||||
|
|
||||||
fileData, _ := yaml.Marshal(&widget.list)
|
fileData, _ := yaml.Marshal(&widget.list)
|
||||||
|
7
wtf.go
7
wtf.go
@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
"github.com/senorprogrammer/wtf/bamboohr"
|
"github.com/senorprogrammer/wtf/bamboohr"
|
||||||
"github.com/senorprogrammer/wtf/bargraph"
|
"github.com/senorprogrammer/wtf/bargraph"
|
||||||
|
"github.com/senorprogrammer/wtf/cfg"
|
||||||
"github.com/senorprogrammer/wtf/clocks"
|
"github.com/senorprogrammer/wtf/clocks"
|
||||||
"github.com/senorprogrammer/wtf/cmdrunner"
|
"github.com/senorprogrammer/wtf/cmdrunner"
|
||||||
"github.com/senorprogrammer/wtf/cryptoexchanges/bittrex"
|
"github.com/senorprogrammer/wtf/cryptoexchanges/bittrex"
|
||||||
@ -260,7 +261,7 @@ func makeWidgets(app *tview.Application, pages *tview.Pages) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func loadConfig(configFlag string) {
|
func loadConfig(configFlag string) {
|
||||||
Config = wtf.LoadConfigFile(configFlag)
|
Config = cfg.LoadConfigFile(configFlag)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -277,8 +278,8 @@ func main() {
|
|||||||
|
|
||||||
// Responsible for creating the configuration directory and default
|
// Responsible for creating the configuration directory and default
|
||||||
// configuration file if they don't already exist
|
// configuration file if they don't already exist
|
||||||
wtf.CreateConfigDir()
|
cfg.CreateConfigDir()
|
||||||
wtf.WriteConfigFile()
|
cfg.WriteConfigFile()
|
||||||
|
|
||||||
loadConfig(cmdFlags.Config)
|
loadConfig(cmdFlags.Config)
|
||||||
os.Setenv("TERM", Config.UString("wtf.term", os.Getenv("TERM")))
|
os.Setenv("TERM", Config.UString("wtf.term", os.Getenv("TERM")))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user