Pārlūkot izejas kodu

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.
morganamilo 7 gadi atpakaļ
vecāks
revīzija
33b76045e7
2 mainītis faili ar 8 papildinājumiem un 13 dzēšanām
  1. 6 10
      cmd.go
  2. 2 3
      config.go

+ 6 - 10
cmd.go

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

+ 2 - 3
config.go

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