-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvalidate.go
More file actions
61 lines (52 loc) · 1.34 KB
/
validate.go
File metadata and controls
61 lines (52 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"fmt"
"os"
"github.com/boringtools/sane/internal/sane"
"github.com/spf13/cobra"
)
type validateCommand struct {
repoPath string
rulesPath string
strict bool
failFast bool
}
func newValidateCommand() *cobra.Command {
currDir, err := os.Getwd()
if err != nil {
panic(err)
}
validate := &validateCommand{}
cmd := &cobra.Command{
Use: "validate [OPTIONS]",
RunE: func(cmd *cobra.Command, args []string) error {
if err := validate.run(args); err != nil {
sane.LoggerWithError(err).Errorf("Validation failed")
os.Exit(1)
}
return err
},
}
fs := cmd.Flags()
fs.StringVarP(&validate.repoPath, "path", "p", currDir,
"Git repository path")
fs.StringVarP(&validate.rulesPath, "rules", "r",
fmt.Sprintf("%s/%s", sane.REPOSITORY_PATH_PLACEHOLDER,
sane.REPOSITORY_SANE_DEFAULT_FILE),
"Sane rules path")
fs.BoolVarP(&validate.strict, "strict", "s", false,
"Enable strict validation mode")
fs.BoolVarP(&validate.failFast, "fail-fast", "f", false,
"Fail as soon as any validation fails")
return cmd
}
func (v *validateCommand) run(args []string) error {
sane.SetLogLevel(verbose, debug)
return sane.Execute(sane.Config{
RepositoryPath: v.repoPath,
RulesPath: v.rulesPath,
RulesType: sane.RULES_FORMAT_GITIGNORE,
Strict: v.strict,
FailFast: v.failFast,
})
}