diff --git a/flag_bool_with_inverse.go b/flag_bool_with_inverse.go index d885bbd..adc6c47 100644 --- a/flag_bool_with_inverse.go +++ b/flag_bool_with_inverse.go @@ -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) diff --git a/flag_bool_with_inverse_test.go b/flag_bool_with_inverse_test.go index 895c33d..423157e 100644 --- a/flag_bool_with_inverse_test.go +++ b/flag_bool_with_inverse_test.go @@ -367,6 +367,12 @@ func TestBoolWithInverseString(t *testing.T) { required: true, expected: "-[no-]e\t", }, + { + testName: "single-char multibyte flag name", + flagName: "ü", + required: true, + expected: "-[no-]ü\t", + }, { testName: "multi-char flag name", flagName: "env", @@ -412,6 +418,13 @@ func TestBoolWithInverseString(t *testing.T) { aliases: []string{"c"}, expected: "--[no-]color, -c\t(default: false)", }, + { + testName: "short multibyte alias", + flagName: "color", + required: false, + aliases: []string{"ü"}, + expected: "--[no-]color, -ü\t(default: false)", + }, { testName: "long alias", flagName: "color",