From 06c06f5f6427f6da22b2476fa208e8c4ce54b7ee Mon Sep 17 00:00:00 2001 From: Nikolaus Gotsche Date: Wed, 12 Sep 2018 02:37:44 +0200 Subject: Conf/DB into Home Dir, general beautification and debug --- config.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'config.go') diff --git a/config.go b/config.go index abbc78b..851c93b 100644 --- a/config.go +++ b/config.go @@ -6,7 +6,9 @@ import ( //"os" "io/ioutil" //"strconv" + "github.com/fatih/color" "github.com/BurntSushi/toml" + "github.com/atrox/homedir" ) type Config struct { @@ -32,7 +34,8 @@ var conffile string var config Config func init() { - conffile = "laboravi.config.toml" + conffile,err = homedir.Expand("~/.laboravi.config.toml") //make ~ when finished + checkErr(err) } func editConf() { @@ -57,13 +60,16 @@ func editConf() { } func initConf() { + boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc() + boldRed := color.New(color.FgRed, color.Bold).SprintFunc() for { if _, err := toml.DecodeFile(conffile, &config); err != nil { //fmt.Println(err) - fmt.Println("Configuration file not found") + fmt.Println(boldRed("Configuration file not found")) makeNewTOML(false) }else{ - fmt.Println("Configuration loaded Successfully") + //fmt.Println(boldGreen("Configuration loaded Successfully")) + fmt.Println("Config loaded...",boldGreen("Hello ",config.Name)) break } } @@ -76,7 +82,9 @@ func makeNewTOML(gibts bool) { fmt.Println("Making new Configuration File") //Examplenames Coming soon n := "" - config = Config{".mytimes.db",n,n,n,n,n,n,n,n,n,n,n,n,n,n,n} + file,err := homedir.Expand("~/.mywork.db") + checkErr(err) + config = Config{file,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n} } //fmt.Println("Whats Your Namecount\n") database := getNewInput("DB File Path: ",config.Database) -- cgit v1.2.3