diff --git a/parse/args/args.go b/parse/args/args.go index 054194a..9cd5394 100644 --- a/parse/args/args.go +++ b/parse/args/args.go @@ -81,6 +81,18 @@ func (p *Parser) next() bool { if !hasValue && p.pos < len(p.Args) { value = p.Args[p.pos] if len(value) > 0 && value[0] != '-' { + // NOTE: this is NOT the same behaviour as for flag.Parse(). + // flag.Parse() works well if we pass `-flag=true`, but not + // if we pass `-flag true`. + if p.isBoolFlag(name) { + p.fail(""+ + "ambiguous boolean flag -%s value: can't guess whether "+ + "the %q is the flag value or the non-flag argument "+ + "(consider using `=` or `--`)", + name, value, + ) + return false + } hasValue = true p.pos++ } diff --git a/parse/args/args_test.go b/parse/args/args_test.go index 808d854..b58dc2c 100644 --- a/parse/args/args_test.go +++ b/parse/args/args_test.go @@ -33,8 +33,8 @@ func TestFlagsParseArgs(t *testing.T) { }, args: []string{ "-a", - "-b", "true", - "-c", "false", + "-b=true", + "-c=false", "-foo", "value", "--bar", "value", "arg1", "arg2", "arg3",