fix: use prefixFor for BoolWithInverseFlag names and aliases

BoolWithInverseFlag.String picked - or -- with len(name) == 1, which counts bytes, while the rest of the library uses prefixFor, which counts runes. a one-character non-ascii name or alias was shown as --ü in its help and as -ü for any other flag.
This commit is contained in:
dualfroz committed 2026-10-07 19:37:46 +02:00
1 parent ba1266f7c4
commit 544f3ffc57
2 files changed
+15 -10

No files matched your search

+2 -10
View File
@@ -203,12 +203,8 @@ func (bif *BoolWithInverseFlag) String() string {
i := strings.Index(out, "\t")
prefix := "--"
// single character flags are prefixed with `-` instead of `--`
if len(bif.Name) == 1 {
prefix = "-"
}
prefix := prefixFor(bif.Name)
// Guard against a FlagStringer that returns a string without a tab (e.g.
// a custom stringer or the default stringer when the flag does not
@@ -220,11 +216,7 @@ func (bif *BoolWithInverseFlag) String() string {
var aliasParts []string
for _, alias := range bif.Aliases {
aPrefix := "--"
if len(alias) == 1 {
aPrefix = "-"
}
aliasParts = append(aliasParts, aPrefix+alias)
aliasParts = append(aliasParts, prefixFor(alias)+alias)
}
names := fmt.Sprintf("%s[%s]%s", prefix, bif.inversePrefix(), bif.Name)