1
0
Fork 0
mirror of https://github.com/vbatts/git-validation.git synced 2024-11-17 13:58:39 +00:00
git-validation/main.go
Vincent Batts d614ccf997 *: run tests in a runner
for cleanliness and ease of testing

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2015-10-06 10:44:04 -04:00

57 lines
1.3 KiB
Go

package main
import (
"flag"
"fmt"
"log"
"os"
_ "github.com/vbatts/git-validation/rules/dco"
_ "github.com/vbatts/git-validation/rules/shortsubject"
"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")
flDebug = flag.Bool("D", false, "debug output")
flDir = flag.String("d", ".", "git directory to validate from")
)
func main() {
flag.Parse()
if *flDebug {
os.Setenv("DEBUG", "1")
}
if *flListRules {
for _, r := range validate.RegisteredRules {
fmt.Printf("%q -- %s\n", r.Name, r.Description)
}
return
}
// reduce the set being run
rules := validate.RegisteredRules
if *flRun != "" {
rules = validate.FilterRules(rules, validate.SanitizeFilters(*flRun))
}
runner, err := validate.NewRunner(*flDir, rules, *flCommitRange, *flVerbose)
if err != nil {
log.Fatal(err)
}
if err := runner.Run(); err != nil {
log.Fatal(err)
}
_, fail := runner.Results.PassFail()
if fail > 0 {
fmt.Printf("%d issues to fix\n", fail)
os.Exit(1)
}
}