Skip to content

Commit

Permalink
(#46) Fix panic: flag '<flag>' cannot be repeated (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
llorllale committed Mar 7, 2019
1 parent f332d57 commit f01f859
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion cmd/go-gitlint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"math"
"os"
"strconv"
"strings"

"github.com/llorllale/go-gitlint/internal/commits"
"github.com/llorllale/go-gitlint/internal/issues"
Expand Down Expand Up @@ -92,11 +93,33 @@ func configure() {
}
args = append(args, config...)
}
if _, err := kingpin.CommandLine.Parse(args); err != nil {
if _, err := kingpin.CommandLine.Parse(unique(args)); err != nil {
panic(err)
}
}

func unique(args []string) []string {
u := make([]string, 0)
flags := make([]string, 0)
for _, a := range args {
name := strings.Split(a, "=")[0]
if !contains(name, flags) {
u = append(u, a)
flags = append(flags, name)
}
}
return u
}

func contains(s string, strs []string) bool {
for _, str := range strs {
if s == str {
return true
}
}
return false
}

func try(cond bool, actual, dflt func() commits.Commits) commits.Commits {
if cond {
return actual()
Expand Down

0 comments on commit f01f859

Please sign in to comment.