From 112d2da2e863eb8696048343764fc1d6fd2226da Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Mon, 21 Oct 2019 15:09:04 -0400 Subject: [PATCH] Basic implementation of config file --- cmdSet.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/cmdSet.go b/cmdSet.go index fabdc06..0a2dacf 100644 --- a/cmdSet.go +++ b/cmdSet.go @@ -5,6 +5,8 @@ package main import ( "fmt" "strings" + + "github.com/pelletier/go-toml" ) func init() { @@ -26,7 +28,8 @@ func cmdSet(cmd []string) { if len(cmd) < 3 { switch cmd[1] { case "load": - printToView("Feed", "Load values from file?") + loadFromToml() + printToView("Feed", fmt.Sprintf("Loading config from toml")) case "downloadPath": printToView("Feed", fmt.Sprintf("Setting for %s -> %s", cmd[1], downloadPath)) case "outputFormat": @@ -62,3 +65,16 @@ func cmdSet(cmd []string) { } } +func loadFromToml() { + config, err := toml.LoadFile("kbtui.tml") + if err != nil { + printToView("Feed", fmt.Sprintf("Could not read config file: %+v", err)) + return + } + colorless = config.Get("Basics.colorless").(bool) + downloadPath = config.Get("Basics.downloadPath").(string) + cmdPrefix = config.Get("Basics.cmdPrefix").(string) + outputFormat = config.Get("Formatting.outputFormat").(string) + dateFormat = config.Get("Formatting.dateFormat").(string) + timeFormat = config.Get("Formatting.timeFormat").(string) +}