From 56997f2e142316f8a2e3233264fe62aa5cffe7ec Mon Sep 17 00:00:00 2001 From: Ionut Nicula Date: Sat, 14 Sep 2024 18:37:37 +0300 Subject: [PATCH] Reduce indentation --- command.go | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/command.go b/command.go index 1f0b80345..cc20afedc 100644 --- a/command.go +++ b/command.go @@ -678,31 +678,33 @@ Loop: shorthandCombination := s[1:] // Skip the leading "-" lastPos := len(shorthandCombination) - 1 for i, shorthand := range shorthandCombination { - if !shortHasNoOptDefVal(string(shorthand), flags) { - // We found a shorthand that needs a value. + if shortHasNoOptDefVal(string(shorthand), flags) { + continue + } - if i == lastPos { - // Since we're at the end of the shorthand combination, this means that the - // value for the shorthand is given in the next argument. (e.g. '-xyzf arg', - // where -x, -y, -z are boolean flags, and -f is a flag that needs a value). + // We found a shorthand that needs a value. - // The whole combination will take a value. - flagsThatConsumeNextArg = append(flagsThatConsumeNextArg, s) + if i == lastPos { + // Since we're at the end of the shorthand combination, this means that the + // value for the shorthand is given in the next argument. (e.g. '-xyzf arg', + // where -x, -y, -z are boolean flags, and -f is a flag that needs a value). - if len(args) <= 1 { - break Loop - } else { - args = args[1:] - } + // The whole combination will take a value. + flagsThatConsumeNextArg = append(flagsThatConsumeNextArg, s) + + if len(args) <= 1 { + break Loop } else { - // Since the shorthand combination doesn't end here, this means that the - // value for the shorthand is given in the same argument, meaning we don't - // have to consume the next one. (e.g. '-xyzfarg', where -x, -y, -z are - // boolean flags, and -f is a flag that needs a value). + args = args[1:] } - - break + } else { + // Since the shorthand combination doesn't end here, this means that the + // value for the shorthand is given in the same argument, meaning we don't + // have to consume the next one. (e.g. '-xyzfarg', where -x, -y, -z are + // boolean flags, and -f is a flag that needs a value). } + + break } case s != "" && !strings.HasPrefix(s, "-"): commands = append(commands, s)