mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-24 09:18:08 +02:00
DRYer
This commit is contained in:
@@ -76,30 +76,25 @@ func (self *Command) parse_args(ctx *Context, args []string) error {
|
|||||||
options_allowed = false
|
options_allowed = false
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
opt_str := arg
|
opt_str, opt_val, has_val := strings.Cut(arg, "=")
|
||||||
if strings.HasPrefix(opt_str, "--") {
|
if strings.HasPrefix(opt_str, "--") {
|
||||||
opt_str, opt_val, has_val := strings.Cut(opt_str, "=")
|
|
||||||
err := handle_option(opt_str, has_val, opt_val, false)
|
err := handle_option(opt_str, has_val, opt_val, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
prefix, payload, has_payload := strings.Cut(opt_str, "=")
|
runes := []rune(opt_str[1:])
|
||||||
runes := []rune(prefix[1:])
|
|
||||||
for i, sl := range runes {
|
for i, sl := range runes {
|
||||||
err := handle_option("-"+string(sl), false, "", i < len(runes)-1)
|
var err error
|
||||||
|
if i == len(runes)-1 {
|
||||||
|
err = handle_option("-"+string(sl), has_val, opt_val, false)
|
||||||
|
} else {
|
||||||
|
err = handle_option("-"+string(sl), false, "", true)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if has_payload {
|
|
||||||
if expecting_arg_for == nil {
|
|
||||||
return &ParseError{Message: fmt.Sprintf("The option: :yellow:`-%c` does not take values", prefix[len(prefix)-1])}
|
|
||||||
} else {
|
|
||||||
expecting_arg_for.add_value(payload)
|
|
||||||
expecting_arg_for = nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// handle non option arg
|
// handle non option arg
|
||||||
|
|||||||
Reference in New Issue
Block a user