diff options
author | Thomas Voss <mail@thomasvoss.com> | 2023-11-29 20:39:43 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2023-11-29 20:39:43 +0100 |
commit | 9910dadfab38423354671377d06d64e669c273ab (patch) | |
tree | 94c0f13f944e34d9748e4918aee578f51b01fa9a | |
parent | 9578d76a8fd70ca766178175f5ba97ce284b6ff6 (diff) |
Slight refactor
-rw-r--r-- | opts.go | 21 |
1 files changed, 11 insertions, 10 deletions
@@ -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 } } |