Add --save option

Before setting options such as --topdown would be saved to the config
file automaticly when used. Now this is no longer done by default and
isntead the --save flag must be passed for this to happen.

If --save is passed the config is now saved as soon as the argument
parsing is finished apposed to before where it was saved when yay exits.
This means that config changes will now apply if the user does a ^C
before yay finishes.
This commit is contained in:
morganamilo 2018-03-07 22:09:03 +00:00
parent a7be7a839d
commit 33b76045e7
No known key found for this signature in database
GPG key ID: 6FE9E7996B0B082E
2 changed files with 8 additions and 13 deletions

16
cmd.go
View file

@ -248,15 +248,6 @@ cleanup:
//if we fail to save the configuration
//at least continue on and try clean up other parts
if changedConfig {
err = config.saveConfig()
if err != nil {
fmt.Println(err)
status = 1
}
}
if alpmHandle != nil {
err = alpmHandle.Release()
if err != nil {
@ -306,6 +297,10 @@ func handleCmd() (err error) {
}
}
if shouldSaveConfig {
config.saveConfig()
}
if config.SudoLoop && cmdArgs.needRoot() {
sudoLoopBackground()
}
@ -350,6 +345,8 @@ func handleCmd() (err error) {
//e.g yay -Yg
func handleConfig(option string) bool {
switch option {
case "save":
shouldSaveConfig = true
case "afterclean":
config.CleanAfter = true
case "noafterclean":
@ -378,7 +375,6 @@ func handleConfig(option string) bool {
return false
}
changedConfig = true
return true
}

View file

@ -74,8 +74,8 @@ var vcsFile string
// completion file
var completionFile string
// changedConfig holds whether or not the config has changed
var changedConfig bool
// shouldSaveConfig holds whether or not the config should be saved
var shouldSaveConfig bool
// YayConf holds the current config values for yay.
var config Configuration
@ -100,7 +100,6 @@ func readAlpmConfig(pacmanconf string) (conf alpm.PacmanConfig, err error) {
// SaveConfig writes yay config to file.
func (config *Configuration) saveConfig() error {
config.NoConfirm = false
marshalledinfo, _ := json.MarshalIndent(config, "", "\t")
in, err := os.OpenFile(configFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {