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

Clean up the flag and config handling in main()

This commit is contained in:
Chris Cummer
2018-06-16 09:13:23 -07:00
parent dd42080ed8
commit 4496cc7c31
3 changed files with 61 additions and 55 deletions

View File

@@ -30,6 +30,25 @@ func CreateConfigDir() {
}
}
// CreateConfigFile creates a simple config file in the config directory if
// one does not already exist
func CreateConfigFile() {
filePath, err := CreateFile("config.yml")
if err != nil {
panic(err)
}
// If the file is empty, write to it
file, err := os.Stat(filePath)
if file.Size() == 0 {
err = ioutil.WriteFile(filePath, []byte(simpleConfig), 0644)
if err != nil {
panic(err)
}
}
}
// CreateFile creates the named file in the config directory, if it does not already exist.
// If the file exists it does not recreate it.
// If successful, eturns the absolute path to the file
@@ -88,25 +107,6 @@ func ReadConfigFile(fileName string) (string, error) {
return string(fileData), nil
}
// WriteConfigFile creates a simple config file in the config directory if
// one does not already exist
func WriteConfigFile() {
filePath, err := CreateFile("config.yml")
if err != nil {
panic(err)
}
// If the file is empty, write to it
file, err := os.Stat(filePath)
if file.Size() == 0 {
err = ioutil.WriteFile(filePath, []byte(simpleConfig), 0644)
if err != nil {
panic(err)
}
}
}
const simpleConfig = `wtf:
colors:
border: