Skip to content

Commit

Permalink
Merge 6b53ad6 into b76d58b
Browse files Browse the repository at this point in the history
  • Loading branch information
jawher committed May 3, 2018
2 parents b76d58b + 6b53ad6 commit 03b4785
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ ineffassign:
ineffassign .

readmecheck:
cp README.md README.original.md
sed '$ d' README.md > README.original.md
autoreadme -f
diff README.md README.original.md
sed '$ d' README.md > README.generated.md
diff README.generated.md README.original.md

setup:
go get github.com/gordonklaus/ineffassign
Expand Down
2 changes: 1 addition & 1 deletion internal/matcher/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (o *opt) Match(args []string, c *ParseContext) (bool, []string) {

func (o *opt) matchLongOpt(args []string, idx int, c *ParseContext) (bool, int, []string) {
arg := args[idx]
kv := strings.Split(arg, "=")
kv := strings.SplitN(arg, "=", 2)
name := kv[0]
opt, found := o.index[name]
if !found {
Expand Down
5 changes: 5 additions & 0 deletions internal/matcher/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,17 @@ func TestOptMatcher(t *testing.T) {
val []string
}{
{[]string{"-f", "x"}, []string{}, []string{"x"}},
{[]string{"-f", "x="}, []string{}, []string{"x="}},
{[]string{"-f=x", "y"}, []string{"y"}, []string{"x"}},
{[]string{"-f=x=", "y"}, []string{"y"}, []string{"x="}},
{[]string{"-fx", "y"}, []string{"y"}, []string{"x"}},
{[]string{"-fx=", "y"}, []string{"y"}, []string{"x="}},
{[]string{"-afx", "y"}, []string{"-a", "y"}, []string{"x"}},
{[]string{"-af", "x", "y"}, []string{"-a", "y"}, []string{"x"}},
{[]string{"--force", "x"}, []string{}, []string{"x"}},
{[]string{"--force", "x="}, []string{}, []string{"x="}},
{[]string{"--force=x", "y"}, []string{"y"}, []string{"x"}},
{[]string{"--force=x=", "y"}, []string{"y"}, []string{"x="}},
}

for _, cas := range cases {
Expand Down
5 changes: 5 additions & 0 deletions internal/matcher/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,18 @@ func TestOptsMatcher(t *testing.T) {
{[]string{"--force=false", "y"}, []string{"y"}, [][]string{{"false"}, nil}},

{[]string{"-g", "x"}, []string{}, [][]string{nil, {"x"}}},
{[]string{"-g", "x="}, []string{}, [][]string{nil, {"x="}}},
{[]string{"-g=x", "y"}, []string{"y"}, [][]string{nil, {"x"}}},
{[]string{"-g=x=", "y"}, []string{"y"}, [][]string{nil, {"x="}}},
{[]string{"-gx", "y"}, []string{"y"}, [][]string{nil, {"x"}}},
{[]string{"--green", "x"}, []string{}, [][]string{nil, {"x"}}},
{[]string{"--green", "x="}, []string{}, [][]string{nil, {"x="}}},
{[]string{"--green=x", "y"}, []string{"y"}, [][]string{nil, {"x"}}},
{[]string{"--green=x=", "y"}, []string{"y"}, [][]string{nil, {"x="}}},

{[]string{"-f", "-g", "x", "y"}, []string{"y"}, [][]string{{"true"}, {"x"}}},
{[]string{"-g", "x", "-f", "y"}, []string{"y"}, [][]string{{"true"}, {"x"}}},
{[]string{"-g", "x=", "-f", "y"}, []string{"y"}, [][]string{{"true"}, {"x="}}},
{[]string{"-fg", "x", "y"}, []string{"y"}, [][]string{{"true"}, {"x"}}},
{[]string{"-fgxxx", "y"}, []string{"y"}, [][]string{{"true"}, {"xxx"}}},
}
Expand Down

0 comments on commit 03b4785

Please sign in to comment.