From efb043e4ff0a6e41d50cac0364647d484b3661c7 Mon Sep 17 00:00:00 2001 From: Jakub Zych Date: Wed, 21 Oct 2026 19:13:21 +0200 Subject: [PATCH] fix(bonfire): PeekGlobals reads clustered shorthands like -qn and -vq pflag accepts -qn as -q -n and -vvq as -v -v -q, but PeekGlobals only read clusters made of v, so the generated main's pre-boot diary setup, the error block of Execute and passthrough commands missed -q, -n and -v when they were clustered. Read the cluster letter by letter and stop at the first letter that is not a global shorthand. --- modules/bonfire/globals.go | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) 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 {