-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmain.go
152 lines (137 loc) · 2.69 KB
/
main.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package main
import (
"github.com/libgit2/git2go"
"github.com/urfave/cli"
"log"
"os"
"path/filepath"
)
var gs *gitSeekret
func main() {
app := cli.NewApp()
app.Name = "git-seekret"
app.Version = "0.0.1"
app.Usage = "prevent from committing sensitive information into git repository"
app.Author = "Albert Puigsech Galicia"
app.Email = "[email protected]"
app.EnableBashCompletion = false
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "global",
},
}
app.Commands = []cli.Command{
{
Name: "config",
Usage: "manage configuration seetings",
Action: GitSeekretConfig,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "init",
Usage: "initialize configuration with default values",
},
cli.StringFlag{
Name: "set, s",
Usage: "set value for specific setting",
Value: "",
},
},
},
{
Name: "rules",
Usage: "manage rules",
Action: GitSeekretRules,
Flags: []cli.Flag{
cli.StringFlag{
Name: "enable, e",
Usage: "enable rules",
Value: "",
},
cli.StringFlag{
Name: "disable, d",
Usage: "disable rule",
Value: "",
},
cli.BoolFlag{
Name: "enable-all",
Usage: "enable all rules",
},
cli.BoolFlag{
Name: "disable-all",
Usage: "disable all rules",
},
},
},
{
Name: "check",
Usage: "inspect git repository",
Action: GitSeekretCheck,
Flags: []cli.Flag{
cli.IntFlag{
Name: "commit, c",
Usage: "include commited files. Argument is the number of commits to inspect (0 = all)",
Value: 0,
},
cli.BoolFlag{
Name: "staged, s",
Usage: "include staged files",
},
},
},
{
Name: "hook",
Usage: "manage git hooks",
Action: GitSeekretHook,
Flags: []cli.Flag{
cli.StringFlag{
Name: "run, r",
Usage: "TBD",
Value: "",
},
cli.StringFlag{
Name: "enable, e",
Usage: "TBD",
Value: "",
},
cli.StringFlag{
Name: "disable, d",
Usage: "TBD",
Value: "",
},
cli.BoolFlag{
Name: "enable-all",
Usage: "TBD",
},
cli.BoolFlag{
Name: "disable-all",
Usage: "TBD",
},
},
},
}
app.Before = gitSeekretBefore
app.After = gitSeekretAfter
app.Run(os.Args)
}
func gitSeekretBefore(c *cli.Context) error {
var configLevel git.ConfigLevel
var err error
var repoPath string
if c.Bool("global") {
configLevel = git.ConfigLevelGlobal
} else {
configLevel = git.ConfigLevelLocal
}
repoPath, err = filepath.Abs(".")
if err != nil {
log.Panic(err)
}
gs, err = NewGitSeekret(repoPath, configLevel)
if err != nil {
log.Panic(err)
}
return nil
}
func gitSeekretAfter(c *cli.Context) error {
return nil
}