未验证 提交 d9226a7f 编写于 作者: M Mislav Marohnić 提交者: GitHub

Merge pull request #2591 from github/fix-bool-value-parsing

Fix parsing boolean flags with explicit values
......@@ -102,6 +102,7 @@ func (p *ArgsParser) Parse(args []string) ([]string, error) {
}
} else if strings.HasPrefix(arg, "--") {
flagName = arg
flagValue = ""
eq := strings.IndexByte(arg, '=')
hasFlagValue = eq >= 0
if hasFlagValue {
......
......@@ -118,6 +118,18 @@ func TestArgsParser_BoolValue(t *testing.T) {
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) {
p := NewArgsParser()
p.RegisterValue("--origin", "-o")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册