aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2023-11-29 20:39:43 +0100
committerThomas Voss <mail@thomasvoss.com> 2023-11-29 20:39:43 +0100
commit9910dadfab38423354671377d06d64e669c273ab (patch)
tree94c0f13f944e34d9748e4918aee578f51b01fa9a
parent9578d76a8fd70ca766178175f5ba97ce284b6ff6 (diff)
Slight refactor
-rw-r--r--opts.go21
1 files changed, 11 insertions, 10 deletions
diff --git a/opts.go b/opts.go
index c7ab697..8085c0a 100644
--- a/opts.go
+++ b/opts.go
@@ -42,27 +42,28 @@ func Get(args []string, optstr string) (flags []Flag, optind int, err error) {
}
rs := []rune(arg[1:])
- outer:
for j, r := range rs {
+ var s string
argp, ok := argmap[r]
- if !ok {
- return nil, 0, ErrBadOption(r)
- }
switch {
+ case !ok:
+ return nil, 0, ErrBadOption(r)
case argp && j < len(rs)-1:
- s := string(rs[j+1:])
- flags = append(flags, Flag{r, s})
- break outer
+ s = string(rs[j+1:])
case argp:
i++
if i >= len(args) {
return nil, 0, ErrNoArgument(r)
}
- flags = append(flags, Flag{r, args[i]})
- break outer
+ s = args[i]
+ default:
+ flags = append(flags, Flag{Key: r})
+ continue
}
- flags = append(flags, Flag{Key: r})
+
+ flags = append(flags, Flag{r, s})
+ break
}
}