-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmain_rules.go
59 lines (48 loc) · 1.32 KB
/
main_rules.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
package main
import (
"fmt"
"github.com/libgit2/git2go"
"github.com/urfave/cli"
)
func GitSeekretRules(c *cli.Context) error {
err := gs.LoadConfig(true)
if git.IsErrorClass(err, git.ErrClassConfig) {
return fmt.Errorf("Config not initialised - Try: 'git-seekret config --init'")
}
if err != nil {
return err
}
enable := c.String("enable")
disable := c.String("disable")
enableAll := c.Bool("enable-all")
disableAll := c.Bool("disable-all")
if enableAll {
fmt.Println("Enabling all rules.")
gs.EnableRule(".*")
} else if disableAll {
fmt.Println("Disabling all rules.")
gs.DisableRule(".*")
}
// "all" represents that either enableAll or disableAll was triggered.
all := (enableAll || disableAll)
// If neither enableAll nor disableAll were used, let's look into doing
// individual enable and/or disable operations.
// Useful because in a single command you can specify both an --enable flag
// and a --disable flag but only want to do it if neither enable-all or disable-all were used.
if !all && enable != "" {
gs.EnableRule(enable)
}
if !all && disable != "" {
gs.DisableRule(disable)
}
fmt.Println("List of rules:")
for _, r := range gs.seekret.ListRules() {
status := " "
if r.Enabled {
status = "x"
}
fmt.Printf("\t[%s] %s\n", status, r.Name)
}
gs.SaveConfig()
return nil
}