-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd_check.go
63 lines (48 loc) · 1.17 KB
/
cmd_check.go
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
62
63
package main
import (
"fmt"
"os"
"text/tabwriter"
"github.com/spf13/cobra"
)
func addCommandCheck(root *cobra.Command, gopts *GlobalOptions, cfg *Config) {
var cmd = &cobra.Command{
Use: "check",
Short: "run checks and print the result",
Long: "run all checks and print the current result for each",
SilenceErrors: true,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
return runCheck(*gopts, *cfg, args)
},
}
root.AddCommand(cmd)
}
func runCheck(gopts GlobalOptions, _ Config, _ []string) error {
checks, err := FilterChecks(AllChecks, gopts.DisableChecks)
if err != nil {
return err
}
tw := tabwriter.NewWriter(os.Stdout, 3, 8, 2, ' ', 0)
cfg := CheckConfig{
Dir: ".",
Version: gopts.Version,
}
results, err := RunChecks(cfg, checks)
for _, result := range results {
text := ""
status := "✓"
if result.Result != nil {
text = result.Result.Error()
status = "✗"
}
fmt.Fprintf(tw, "%s\t%v\t", status, result.Check.Name)
if gopts.Verbose {
fmt.Fprintf(tw, "%v\t", result.Check.Description)
}
fmt.Fprintln(tw, text)
}
tw.Flush()
fmt.Println()
return err
}