From 404386194b9492b29b03d4e1e65558c545a70b51 Mon Sep 17 00:00:00 2001 From: Nikolaus Gotsche Date: Fri, 19 Oct 2018 12:30:46 +0200 Subject: Trys in Auto-Documentation --- config.go | 210 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 104 insertions(+), 106 deletions(-) (limited to 'config.go') diff --git a/config.go b/config.go index 37962ef..a0b3626 100644 --- a/config.go +++ b/config.go @@ -1,134 +1,132 @@ package main import ( - "bytes" - "fmt" - //"os" - "io/ioutil" - //"strconv" - "github.com/fatih/color" - "github.com/BurntSushi/toml" - "github.com/atrox/homedir" + "bytes" + "fmt" + //"os" + "io/ioutil" + //"strconv" + "github.com/BurntSushi/toml" + "github.com/atrox/homedir" + "github.com/fatih/color" ) type Config struct { - Database string //`toml:"database"` - Name string //`toml:"name"` - Street string //`toml:"street"` - Zip string //`toml:"zip"` - City string //`toml:"city"` - Country string //`toml:"country"` - Telefon string //`toml:"telefon"` - Mobile string //`toml:"mobile"` - Mail string //`toml:"mail"` - Url string //`toml:"url"` - Taxid string //`toml:"taxid"` - Bankacc string //`toml:"bankacc"` - Banklz string //`toml:"banklz"` - Bankname string //`toml:"bankname"` - Iban string //`toml:"iban"` - Bic string //`toml:"bic"` + Database string //`toml:"database"` + Name string //`toml:"name"` + Street string //`toml:"street"` + Zip string //`toml:"zip"` + City string //`toml:"city"` + Country string //`toml:"country"` + Telefon string //`toml:"telefon"` + Mobile string //`toml:"mobile"` + Mail string //`toml:"mail"` + Url string //`toml:"url"` + Taxid string //`toml:"taxid"` + Bankacc string //`toml:"bankacc"` + Banklz string //`toml:"banklz"` + Bankname string //`toml:"bankname"` + Iban string //`toml:"iban"` + Bic string //`toml:"bic"` } var conffile string var config Config func init() { - conffile,err = homedir.Expand("~/.laboravi.config.toml") //make ~ when finished - checkErr(err) + conffile, err = homedir.Expand("~/.laboravi.config.toml") //make ~ when finished + checkErr(err) } func editConf() { - for { - if _, err := toml.DecodeFile(conffile, &config); err != nil { - //fmt.Println(err) - fmt.Println("Configuration file not found") - makeNewTOML(false) - }else{ - showConfig() - if isInterSure("Is this Configuration Correct?") { - break - }else{ - //if isSure("Enter new Configuration?"){ - makeNewTOML(true) - //}else{ - // fmt.Println("I Really Dont think I can Help You then...!") - //} - } - } - } + for { + if _, err := toml.DecodeFile(conffile, &config); err != nil { + //fmt.Println(err) + fmt.Println("Configuration file not found") + makeNewTOML(false) + } else { + showConfig() + if isInterSure("Is this Configuration Correct?") { + break + } else { + //if isSure("Enter new Configuration?"){ + makeNewTOML(true) + //}else{ + // fmt.Println("I Really Dont think I can Help You then...!") + //} + } + } + } } 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(boldRed("Configuration file not found")) - makeNewTOML(false) - }else{ - //fmt.Println(boldGreen("Configuration loaded Successfully")) - fmt.Println("Config loaded...",boldGreen("Hello ",config.Name)) - break - } - } + 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(boldRed("Configuration file not found")) + makeNewTOML(false) + } else { + //fmt.Println(boldGreen("Configuration loaded Successfully")) + fmt.Println("Config loaded...", boldGreen("Hello ", config.Name)) + break + } + } } func makeNewTOML(gibts bool) { - if gibts { - fmt.Println("Editing Configuration File\nPress [Enter] to keep the Current setting") - }else{ - fmt.Println("\nMaking new Configuration File") - //Examplenames Coming soon - 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 := getNewInterInput("DB File Path: ",config.Database) - name := getNewInterInput("Whats your Name?: ",config.Name) - street := getNewInterInput("Street: ",config.Street) - zip := getNewInterInput("Zip Code: ",config.Zip) - city := getNewInterInput("City: ",config.City) - country := getNewInterInput("Country: ",config.City) - telefon := getNewInterInput("Telefone number: ",config.Telefon) - mobile := getNewInterInput("Mobile number: ",config.Mobile) - mail := getNewInterInput("Email: ",config.Mail) - url := getNewInterInput("URL: ",config.Url) - taxid := getNewInterInput("Tax ID: ",config.Taxid) - bankname := getNewInterInput("Bank Name: ",config.Bankname) - bankacc := getNewInterInput("Bank Account: ",config.Bankacc) - banklz := getNewInterInput("BLZ: ",config.Banklz) - iban := getNewInterInput("IBAN: ",config.Iban) - bic := getNewInterInput("BIC: ",config.Bic) + if gibts { + fmt.Println("Editing Configuration File\nPress [Enter] to keep the Current setting") + } else { + fmt.Println("\nMaking new Configuration File") + //Examplenames Coming soon + 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 := getNewInterInput("DB File Path: ", config.Database) + name := getNewInterInput("Whats your Name?: ", config.Name) + street := getNewInterInput("Street: ", config.Street) + zip := getNewInterInput("Zip Code: ", config.Zip) + city := getNewInterInput("City: ", config.City) + country := getNewInterInput("Country: ", config.City) + telefon := getNewInterInput("Telefone number: ", config.Telefon) + mobile := getNewInterInput("Mobile number: ", config.Mobile) + mail := getNewInterInput("Email: ", config.Mail) + url := getNewInterInput("URL: ", config.Url) + taxid := getNewInterInput("Tax ID: ", config.Taxid) + bankname := getNewInterInput("Bank Name: ", config.Bankname) + bankacc := getNewInterInput("Bank Account: ", config.Bankacc) + banklz := getNewInterInput("BLZ: ", config.Banklz) + iban := getNewInterInput("IBAN: ", config.Iban) + bic := getNewInterInput("BIC: ", config.Bic) - conf := Config{database,name,street,zip,city,country,telefon,mobile,mail,url,taxid,bankacc,banklz,bankname,iban,bic} + conf := Config{database, name, street, zip, city, country, telefon, mobile, mail, url, taxid, bankacc, banklz, bankname, iban, bic} - buf := new(bytes.Buffer) - err = toml.NewEncoder(buf).Encode(conf) - if err != nil { - panic(err) - }else{ - //fmt.Println("Conffile:\n",buf.String()) - fmt.Println("\nWriting Configuration File") - err = ioutil.WriteFile(conffile, buf.Bytes(), 0644) - checkErr(err) - } - fmt.Println(" ") + buf := new(bytes.Buffer) + err = toml.NewEncoder(buf).Encode(conf) + if err != nil { + panic(err) + } else { + //fmt.Println("Conffile:\n",buf.String()) + fmt.Println("\nWriting Configuration File") + err = ioutil.WriteFile(conffile, buf.Bytes(), 0644) + checkErr(err) + } + fmt.Println(" ") } func showConfig() { - buf := new(bytes.Buffer) - err := toml.NewEncoder(buf).Encode(config) - if err != nil { - panic(err) - }else{ - fmt.Println("Configuration:\n",buf.String()) - //fmt.Println(config) - } + buf := new(bytes.Buffer) + err := toml.NewEncoder(buf).Encode(config) + if err != nil { + panic(err) + } else { + fmt.Println("Configuration:\n", buf.String()) + //fmt.Println(config) + } } - - -- cgit v1.2.3