forked from gruntwork-io/git-xargs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
93 lines (77 loc) · 2.78 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
package main
import (
"github.com/gruntwork-io/git-xargs/cmd"
"github.com/gruntwork-io/git-xargs/common"
"github.com/gruntwork-io/go-commons/entrypoint"
"github.com/gruntwork-io/go-commons/errors"
"github.com/gruntwork-io/go-commons/logging"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
// VERSION is set at build time using -ldflags parameters. For example, we typically set this flag in circle.yml
// to the latest Git tag when building our Go apps:
//
// build-go-binaries --app-name my-app --dest-path bin --ld-flags "-X main.VERSION=$CIRCLE_TAG"
//
// For more info, see: http://stackoverflow.com/a/11355611/483528
var VERSION string
var LogLevelFlag = cli.StringFlag{
Name: "loglevel",
Value: logrus.InfoLevel.String(),
}
// initCli initializes the CLI app before any command is actually executed. This function will handle all the setup
// code, such as setting up the logger with the appropriate log level.
func initCli(cliContext *cli.Context) error {
// Set logging level
logLevel := cliContext.String(LogLevelFlag.Name)
level, err := logrus.ParseLevel(logLevel)
if err != nil {
return errors.WithStackTrace(err)
}
logging.SetGlobalLogLevel(level)
return nil
}
func setupApp() *cli.App {
app := entrypoint.NewApp()
entrypoint.HelpTextLineWidth = 120
// Override the CLI FlagEnvHinter, so it only returns the Usage text of the Flag and doesn't append the envVar text. Original func https://github.com/urfave/cli/blob/master/flag.go#L652
cli.FlagEnvHinter = func(envVar, str string) string {
return str
}
app.Name = "git-xargs"
app.Author = "Gruntwork <www.gruntwork.io>"
app.Description = "git-xargs is a command-line tool (CLI) for making updates across multiple Github repositories with a single command."
// Set the version number from your app from the VERSION variable that is passed in at build time
app.Version = VERSION
app.EnableBashCompletion = true
app.Before = initCli
app.Flags = []cli.Flag{
LogLevelFlag,
common.GenericGithubOrgFlag,
common.GenericDraftPullRequestFlag,
common.GenericDryRunFlag,
common.GenericSkipPullRequestFlag,
common.GenericSkipArchivedReposFlag,
common.GenericRepoFlag,
common.GenericRepoFileFlag,
common.GenericBranchFlag,
common.GenericBaseBranchFlag,
common.GenericCommitMessageFlag,
common.GenericPullRequestTitleFlag,
common.GenericPullRequestDescriptionFlag,
common.GenericPullRequestReviewersFlag,
common.GenericPullRequestTeamReviewersFlag,
common.GenericSecondsToWaitFlag,
common.GenericMaxPullRequestRetriesFlag,
common.GenericSecondsToWaitWhenRateLimitedFlag,
common.GenericNoSkipCIFlag,
common.GenericKeepClonedRepositoriesFlag,
}
app.Action = cmd.RunGitXargs
return app
}
// main should only setup the CLI flags and help texts.
func main() {
app := setupApp()
entrypoint.RunApp(app)
}