diff --git a/modules/bonfire/globals.go b/modules/bonfire/globals.go index 546e1b4b..12bb627e 100644 --- a/modules/bonfire/globals.go +++ b/modules/bonfire/globals.go @@ -73,18 +73,36 @@ func PeekGlobals(args []string) Globals { } case strings.HasPrefix(a, "--"+flagEnv+"="): g.Env = strings.TrimPrefix(a, "--"+flagEnv+"=") - case isVerboseShorthand(a): - g.Verbosity += len(a) - 1 + case isShorthandCluster(a): + g.peekShorthands(a[1:]) } } return g.normalize() } -func isVerboseShorthand(a string) bool { - if len(a) < 2 || a[0] != '-' || a[1] == '-' { - return false +// isShorthandCluster reports a single-dash token such as -v, -vvv or -qn. +func isShorthandCluster(a string) bool { + return len(a) >= 2 && a[0] == '-' && a[1] != '-' +} + +// peekShorthands reads a cluster of shorthands the way pflag does (-qn is +// -q -n, -vvq is -v -v -q). It stops at the first letter that is not a +// global shorthand: that may be a command flag whose value is the rest of +// the token. +func (g *Globals) peekShorthands(cluster string) { + for _, r := range cluster { + switch r { + case 'v': + g.Verbosity++ + case 'q': + g.Quiet = true + case 'n': + g.NoInteraction = true + case 'h': + default: + return + } } - return strings.Trim(a[1:], "v") == "" } func (g Globals) normalize() Globals {