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:
@@ -73,18 +73,36 @@ func PeekGlobals(args []string) Globals {
|
|||||||
}
|
}
|
||||||
case strings.HasPrefix(a, "--"+flagEnv+"="):
|
case strings.HasPrefix(a, "--"+flagEnv+"="):
|
||||||
g.Env = strings.TrimPrefix(a, "--"+flagEnv+"=")
|
g.Env = strings.TrimPrefix(a, "--"+flagEnv+"=")
|
||||||
case isVerboseShorthand(a):
|
case isShorthandCluster(a):
|
||||||
g.Verbosity += len(a) - 1
|
g.peekShorthands(a[1:])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return g.normalize()
|
return g.normalize()
|
||||||
}
|
}
|
||||||
|
|
||||||
func isVerboseShorthand(a string) bool {
|
// isShorthandCluster reports a single-dash token such as -v, -vvv or -qn.
|
||||||
if len(a) < 2 || a[0] != '-' || a[1] == '-' {
|
func isShorthandCluster(a string) bool {
|
||||||
return false
|
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 {
|
func (g Globals) normalize() Globals {
|
||||||
|
|||||||
Reference in New Issue
Block a user