提交 924e8b88 编写于 作者: M Mislav Marohnić

Fix parsing boolean flags with explicit values

Fixes #2590
上级 222d1102
...@@ -102,6 +102,7 @@ func (p *ArgsParser) Parse(args []string) ([]string, error) { ...@@ -102,6 +102,7 @@ func (p *ArgsParser) Parse(args []string) ([]string, error) {
} }
} else if strings.HasPrefix(arg, "--") { } else if strings.HasPrefix(arg, "--") {
flagName = arg flagName = arg
flagValue = ""
eq := strings.IndexByte(arg, '=') eq := strings.IndexByte(arg, '=')
hasFlagValue = eq >= 0 hasFlagValue = eq >= 0
if hasFlagValue { if hasFlagValue {
......
...@@ -118,6 +118,18 @@ func TestArgsParser_BoolValue(t *testing.T) { ...@@ -118,6 +118,18 @@ func TestArgsParser_BoolValue(t *testing.T) {
equal(t, "yes pls", p.Value("--draft")) equal(t, "yes pls", p.Value("--draft"))
} }
func TestArgsParser_BoolValue_multiple(t *testing.T) {
p := NewArgsParser()
p.RegisterBool("--draft")
p.RegisterBool("--prerelease")
args := []string{"--draft=false", "--prerelease"}
rest, err := p.Parse(args)
equal(t, nil, err)
equal(t, []string{}, rest)
equal(t, false, p.Bool("--draft"))
equal(t, true, p.Bool("--prerelease"))
}
func TestArgsParser_Shorthand(t *testing.T) { func TestArgsParser_Shorthand(t *testing.T) {
p := NewArgsParser() p := NewArgsParser()
p.RegisterValue("--origin", "-o") p.RegisterValue("--origin", "-o")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册