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.
This commit is contained in:
Jakub Zych
2026-10-21 19:13:21 +02:00
parent db83a14056
commit efb043e4ff

View File

@@ -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 {