From 39bf61207195a9a6dfecae2d4ef8a760c159d8e5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 28 Apr 2025 11:33:58 +0530 Subject: [PATCH] DRYer --- tools/cli/parse-args.go | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/tools/cli/parse-args.go b/tools/cli/parse-args.go index 1ed9ead9a..9e8b0af49 100644 --- a/tools/cli/parse-args.go +++ b/tools/cli/parse-args.go @@ -76,30 +76,25 @@ func (self *Command) parse_args(ctx *Context, args []string) error { options_allowed = false continue } - opt_str := arg + opt_str, opt_val, has_val := strings.Cut(arg, "=") 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) if err != nil { return err } } else { - prefix, payload, has_payload := strings.Cut(opt_str, "=") - runes := []rune(prefix[1:]) + runes := []rune(opt_str[1:]) 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 { 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 { // handle non option arg