-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
71 lines (57 loc) · 2.08 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
package main
import (
"fmt"
"os"
"skeely/common/github"
"skeely/common/terminal"
"skeely/config"
"skeely/flags"
"skeely/linter"
"skeely/version"
"github.com/spf13/cobra"
)
func main() {
var f = flags.GetInstance()
var rootCmd = &cobra.Command{
Use: "skeely [COMMANDS] [OPTIONS]",
Long: `skeely is a schema linter for MySQL, this tool help to identifying
some common and uncommon mistakes on data model.
For more help, plese visit: https://github.com/debeando/skeely`,
Example: `
# Lint directory
$ skeely --path=assets/examples/
# Lint specific file
$ skeely --files=assets/examples/case01.sql
# Lint specific file and ignore codes
$ skeely --files=assets/examples/case01.sql --ignore=103,104,305,406
# Lint and push summary as comment into GitHub Pull Request.
$ skeely --path=assets/examples/case01.sql \
--github-comment \
--github-token=${{github.token}} \
--github-repository=$GITHUB_REPOSITORY \
--github-pull-request=${{github.event.pull_request.number}}
`,
Run: func(cmd *cobra.Command, args []string) {
gh := github.GitHub{}
c := config.GetInstance()
if err := c.Load(); err != nil {
fmt.Println(err)
os.Exit(2)
}
msgPlugins := linter.Run()
gh.Comment(msgPlugins)
gh.Push()
terminal.Print(msgPlugins)
},
}
f.Load()
rootCmd.Flags().BoolVarP(&f.GitHubComment, "github-comment", "", false, "Send summary as comment into GitHub.")
rootCmd.Flags().IntVar(&f.GitHubPullRequest, "github-pull-request", 0, "Pull request number.")
rootCmd.Flags().StringVar(&f.Files, "files", "", "List of files to lint, separated by space.")
rootCmd.Flags().StringVar(&f.GitHubRepository, "github-repository", "", "Repository path on github.")
rootCmd.Flags().StringVar(&f.GitHubToken, "github-token", "", "Token to auth in github.")
rootCmd.Flags().StringVar(&f.Ignore, "ignore", "", "List of error codes separated by comma to ignore.")
rootCmd.Flags().StringVar(&f.Path, "path", "", "Path of the directory to start to find *.sql to lint.")
rootCmd.AddCommand(version.NewCommand())
rootCmd.Execute()
}