Fixes #122 properly

Options such as --devel are now striped from the parser before handling
the command but the option is still processed so that config.devel would
be true.

Also changed `changedConfig` to a global in config.go
This commit is contained in:
morganamilo 2018-01-31 17:41:13 +00:00
parent ce1b09c94d
commit 0f0100b4d0
No known key found for this signature in database
GPG key ID: 6FE9E7996B0B082E
3 changed files with 15 additions and 19 deletions

23
cmd.go
View file

@ -199,7 +199,6 @@ func initAlpm() (err error) {
func main() { func main() {
var status int var status int
var err error var err error
var changedConfig bool
err = cmdArgs.parseCommandLine() err = cmdArgs.parseCommandLine()
if err != nil { if err != nil {
@ -222,7 +221,7 @@ func main() {
goto cleanup goto cleanup
} }
changedConfig, err = handleCmd() err = handleCmd()
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
status = 1 status = 1
@ -266,15 +265,17 @@ cleanup:
os.Exit(status) os.Exit(status)
} }
func handleCmd() (changedConfig bool, err error) { func handleCmd() (err error) {
changedConfig = false
for option := range cmdArgs.options { for option := range cmdArgs.options {
changedConfig = changedConfig || handleConfig(option) if handleConfig(option) {
cmdArgs.delArg(option)
}
} }
for option := range cmdArgs.globals { for option := range cmdArgs.globals {
changedConfig = changedConfig || handleConfig(option) if handleConfig(option) {
cmdArgs.delArg(option)
}
} }
switch cmdArgs.op { switch cmdArgs.op {
@ -315,7 +316,7 @@ func handleCmd() (changedConfig bool, err error) {
//my current plan is to have yay specific operations in its own operator //my current plan is to have yay specific operations in its own operator
//e.g. yay -Y --gendb //e.g. yay -Y --gendb
//e.g yay -Yg //e.g yay -Yg
func handleConfig(option string) (changedConfig bool) { func handleConfig(option string) bool {
switch option { switch option {
case "afterclean": case "afterclean":
config.CleanAfter = true config.CleanAfter = true
@ -341,7 +342,7 @@ func handleConfig(option string) (changedConfig bool) {
config.TimeUpdate = false config.TimeUpdate = false
case "topdown": case "topdown":
config.SortMode = TopDown config.SortMode = TopDown
case "--bottomup": case "bottomup":
config.SortMode = BottomUp config.SortMode = BottomUp
// case "help": // case "help":
// usage() // usage()
@ -352,11 +353,11 @@ func handleConfig(option string) (changedConfig bool) {
case "noconfirm": case "noconfirm":
config.NoConfirm = true config.NoConfirm = true
default: default:
return return false
} }
changedConfig = true changedConfig = true
return return true
} }
func handleVersion() { func handleVersion() {

View file

@ -61,6 +61,9 @@ var completionFile string
// Updated returns if database has been updated // Updated returns if database has been updated
var updated bool var updated bool
// changedConfig holds whether or not the config has changed
var changedConfig bool
// YayConf holds the current config values for yay. // YayConf holds the current config values for yay.
var config Configuration var config Configuration

View file

@ -447,10 +447,6 @@ func (parser *arguments) parseShortOption(arg string, param string) (usedNext bo
arg = arg[1:] arg = arg[1:]
if isYayParam(arg) {
return
}
for k, _char := range arg { for k, _char := range arg {
char := string(_char) char := string(_char)
@ -485,10 +481,6 @@ func (parser *arguments) parseLongOption(arg string, param string) (usedNext boo
arg = arg[2:] arg = arg[2:]
if isYayParam(arg) {
return
}
if hasParam(arg) { if hasParam(arg) {
err = parser.addParam(arg, param) err = parser.addParam(arg, param)
usedNext = true usedNext = true