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

This commit is contained in:
ayntgl 2022-02-09 11:46:49 +04:00 • committed by GitHub
parent 92c3be341c
commit 7dd1b0eb64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View file

@ -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

View file

@ -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) {