mirror of
https://github.com/Jguer/yay
synced 2024-10-31 04:12:51 +00:00
Fill default config before trying to unmarshal config file
This keeps the default config values available if the config file only has a few options. Also, if the config is not found, save the default config in its place. And pretty print it when saving to make it easier to edit for users.
This commit is contained in:
parent
3ab83cd14f
commit
2bf1cf4515
1 changed files with 5 additions and 2 deletions
|
@ -51,12 +51,15 @@ var AlpmConf alpm.PacmanConfig
|
||||||
var AlpmHandle *alpm.Handle
|
var AlpmHandle *alpm.Handle
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
defaultSettings(&YayConf)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
configfile := os.Getenv("HOME") + "/.config/yay/config.json"
|
configfile := os.Getenv("HOME") + "/.config/yay/config.json"
|
||||||
|
|
||||||
if _, err = os.Stat(configfile); os.IsNotExist(err) {
|
if _, err = os.Stat(configfile); os.IsNotExist(err) {
|
||||||
_ = os.MkdirAll(os.Getenv("HOME")+"/.config/yay", 0755)
|
_ = os.MkdirAll(os.Getenv("HOME")+"/.config/yay", 0755)
|
||||||
defaultSettings(&YayConf)
|
// Save the default config if nothing is found
|
||||||
|
SaveConfig()
|
||||||
} else {
|
} else {
|
||||||
file, err := os.Open(configfile)
|
file, err := os.Open(configfile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -100,7 +103,7 @@ func readAlpmConfig(pacmanconf string) (conf alpm.PacmanConfig, err error) {
|
||||||
func SaveConfig() error {
|
func SaveConfig() error {
|
||||||
YayConf.NoConfirm = false
|
YayConf.NoConfirm = false
|
||||||
configfile := os.Getenv("HOME") + "/.config/yay/config.json"
|
configfile := os.Getenv("HOME") + "/.config/yay/config.json"
|
||||||
marshalledinfo, _ := json.Marshal(YayConf)
|
marshalledinfo, _ := json.MarshalIndent(YayConf, "", "\t")
|
||||||
in, err := os.OpenFile(configfile, os.O_RDWR|os.O_CREATE, 0755)
|
in, err := os.OpenFile(configfile, os.O_RDWR|os.O_CREATE, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue