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() {
var status int
var err error
var changedConfig bool
err = cmdArgs.parseCommandLine()
if err != nil {
@ -222,7 +221,7 @@ func main() {
goto cleanup
}
changedConfig, err = handleCmd()
err = handleCmd()
if err != nil {
fmt.Println(err)
status = 1
@ -266,15 +265,17 @@ cleanup:
os.Exit(status)
}
func handleCmd() (changedConfig bool, err error) {
changedConfig = false
func handleCmd() (err error) {
for option := range cmdArgs.options {
changedConfig = changedConfig || handleConfig(option)
if handleConfig(option) {
cmdArgs.delArg(option)
}
}
for option := range cmdArgs.globals {
changedConfig = changedConfig || handleConfig(option)
if handleConfig(option) {
cmdArgs.delArg(option)
}
}
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
//e.g. yay -Y --gendb
//e.g yay -Yg
func handleConfig(option string) (changedConfig bool) {
func handleConfig(option string) bool {
switch option {
case "afterclean":
config.CleanAfter = true
@ -341,7 +342,7 @@ func handleConfig(option string) (changedConfig bool) {
config.TimeUpdate = false
case "topdown":
config.SortMode = TopDown
case "--bottomup":
case "bottomup":
config.SortMode = BottomUp
// case "help":
// usage()
@ -352,11 +353,11 @@ func handleConfig(option string) (changedConfig bool) {
case "noconfirm":
config.NoConfirm = true
default:
return
return false
}
changedConfig = true
return
return true
}
func handleVersion() {

View file

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

View file

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