Skip to content

Commit

Permalink
Reduce indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
inicula committed Sep 14, 2024
1 parent eb861cd commit 56997f2
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 56997f2

Please sign in to comment.