Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion command_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"strings"
"unicode"
"unicode/utf8"
)

const (
Expand Down Expand Up @@ -133,7 +134,7 @@ func (cmd *Command) parseFlags(args Args) (Args, error) {
if firstArg[1] == '-' {
numMinuses++
shortOptionHandling = false
} else if !unicode.IsLetter(rune(firstArg[1])) {
} else if firstRune, _ := utf8.DecodeRuneInString(firstArg[1:]); !unicode.IsLetter(firstRune) {
// this is not a flag
tracef("parseFlags not a unicode letter. Stop parsing")
posArgs = append(posArgs, rargs...)
Expand Down
21 changes: 21 additions & 0 deletions command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,27 @@ func TestCommand_FlagValuesKeepWhitespace(t *testing.T) {
}
}

func TestCommand_SingleRuneUnicodeFlag(t *testing.T) {
const name = "ש"
assert.Equal(t, "-", prefixFor(name))

var value string
var args []string
cmd := &Command{
Name: "app",
Flags: []Flag{&StringFlag{Name: name}},
Action: func(_ context.Context, cmd *Command) error {
value = cmd.String(name)
args = cmd.Args().Slice()
return nil
},
}

require.NoError(t, cmd.Run(buildTestContext(t), []string{"app", "-" + name, "value", "operand"}))
assert.Equal(t, "value", value)
assert.Equal(t, []string{"operand"}, args)
}

func TestCommand_EqualsFlagValueValidation(t *testing.T) {
for _, kind := range []string{"int", "bool"} {
for _, whitespace := range []string{"", " ", "\t"} {
Expand Down
3 changes: 2 additions & 1 deletion docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"os"
"runtime"
"strings"
"unicode/utf8"
)

func prefixFor(name string) (prefix string) {
if len(name) == 1 {
if utf8.RuneCountInString(name) == 1 {
prefix = "-"
} else {
prefix = "--"
Expand Down