浏览代码

feat: follow XDG convention for configuration file (#123)

ayntgl 4 年之前
父节点
当前提交
7dd1b0eb64
共有 2 个文件被更改,包括 8 次插入2 次删除
  1. 1 1
      README.md
  2. 7 1
      util/config.go

+ 1 - 1
README.md

@@ -72,7 +72,7 @@ sudo mv ./discordo /usr/local/bin
 
 ### Configuration
 
-A default configuration file is created on first start-up at `$HOME/.config/discordo.toml` on Unix, `$HOME/Library/Application Support/discordo.toml` on Darwin, and `%AppData%/discordo.toml` on Windows.
+A default configuration file is created on first start-up at `$HOME/.config/discordo/config.toml` on Unix, `$HOME/Library/Application Support/discordo/config.toml` on Darwin, and `%AppData%/discordo/config.toml` on Windows.
 
 ## Disclaimer
 

+ 7 - 1
util/config.go

@@ -2,6 +2,7 @@ package util
 
 import (
 	"os"
+	"path/filepath"
 
 	"github.com/BurntSushi/toml"
 )
@@ -37,8 +38,13 @@ func LoadConfig() Config {
 	if err != nil {
 		panic(err)
 	}
+	configPath += "/discordo/config.toml"
+	// Create a directory as well as create all of the nested directories, recursively.
+	err = os.MkdirAll(filepath.Dir(configPath), os.ModePerm)
+	if err != nil {
+		panic(err)
+	}
 
-	configPath += "/discordo.toml"
 	c := Config{}
 	// If the configuration file does not exist, create and write the default configuration to the file.
 	if _, err = os.Stat(configPath); os.IsNotExist(err) {