2015-10-05 20:16:52 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
_ "github.com/vbatts/git-validation/rules/dco"
|
2015-10-05 23:02:31 +00:00
|
|
|
_ "github.com/vbatts/git-validation/rules/shortsubject"
|
2015-10-05 20:16:52 +00:00
|
|
|
"github.com/vbatts/git-validation/validate"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
flCommitRange = flag.String("range", "", "use this commit range instead")
|
|
|
|
flListRules = flag.Bool("list-rules", false, "list the rules registered")
|
|
|
|
flRun = flag.String("run", "", "comma delimited list of rules to run. Defaults to all.")
|
|
|
|
flVerbose = flag.Bool("v", false, "verbose")
|
2015-10-06 14:44:04 +00:00
|
|
|
flDebug = flag.Bool("D", false, "debug output")
|
|
|
|
flDir = flag.String("d", ".", "git directory to validate from")
|
2015-10-05 20:16:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
|
2015-10-06 14:44:04 +00:00
|
|
|
if *flDebug {
|
|
|
|
os.Setenv("DEBUG", "1")
|
2015-10-05 22:45:33 +00:00
|
|
|
}
|
|
|
|
|
2015-10-05 20:16:52 +00:00
|
|
|
if *flListRules {
|
|
|
|
for _, r := range validate.RegisteredRules {
|
|
|
|
fmt.Printf("%q -- %s\n", r.Name, r.Description)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-10-05 22:55:05 +00:00
|
|
|
// reduce the set being run
|
2015-10-05 22:29:24 +00:00
|
|
|
rules := validate.RegisteredRules
|
|
|
|
if *flRun != "" {
|
|
|
|
rules = validate.FilterRules(rules, validate.SanitizeFilters(*flRun))
|
|
|
|
}
|
|
|
|
|
2015-10-06 14:44:04 +00:00
|
|
|
runner, err := validate.NewRunner(*flDir, rules, *flCommitRange, *flVerbose)
|
2015-10-05 20:16:52 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2015-10-06 14:44:04 +00:00
|
|
|
if err := runner.Run(); err != nil {
|
|
|
|
log.Fatal(err)
|
2015-10-05 20:16:52 +00:00
|
|
|
}
|
2015-10-06 14:44:04 +00:00
|
|
|
_, fail := runner.Results.PassFail()
|
2015-10-05 20:16:52 +00:00
|
|
|
if fail > 0 {
|
|
|
|
fmt.Printf("%d issues to fix\n", fail)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2015-10-06 14:44:04 +00:00
|
|
|
|
2015-10-05 20:16:52 +00:00
|
|
|
}
|