style(parser): simplify option creation

This commit is contained in:
jguer 2020-07-26 23:40:21 +02:00
parent c159c06222
commit de92f24ce5
No known key found for this signature in database
GPG Key ID: 6D6CC9BEA8556B35
2 changed files with 12 additions and 11 deletions

View File

@ -143,13 +143,7 @@ func install(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle, ignoreProvide
}
if len(ignore) > 0 {
if arguments.Options["ignore"] == nil {
arguments.Options["ignore"] = &settings.Option{
Args: ignore.ToSlice(),
}
} else {
arguments.Options["ignore"].Add(ignore.ToSlice()...)
}
arguments.CreateOrAppendOption("ignore", ignore.ToSlice()...)
}
}

View File

@ -52,6 +52,16 @@ func (a *Arguments) String() string {
return fmt.Sprintf("Op:%v Options:%+v Targets: %v", a.Op, a.Options, a.Targets)
}
func (a *Arguments) CreateOrAppendOption(option string, values ...string) {
if a.Options[option] == nil {
a.Options[option] = &Option{
Args: values,
}
} else {
a.Options[option].Add(values...)
}
}
func MakeArguments() *Arguments {
return &Arguments{
"",
@ -166,10 +176,7 @@ func (a *Arguments) addParam(option, arg string) error {
return a.addOP(option)
}
if a.Options[option] == nil {
a.Options[option] = &Option{}
}
a.Options[option].Add(strings.Split(arg, ",")...)
a.CreateOrAppendOption(option, strings.Split(arg, ",")...)
if isGlobal(option) {
a.Options[option].Global = true