forked from sagikazarmark/mga
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (41 loc) · 1.16 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
package main
import (
"fmt"
"os"
"github.com/fatih/color"
"github.com/spf13/cobra"
"sagikazarmark.dev/mga/internal/cmd/commands"
)
// Provisioned by ldflags
// nolint: gochecknoglobals
var (
version string
commitHash string
buildDate string
)
const (
// appName is an identifier-like name used anywhere this app needs to be identified.
//
// It identifies the service itself, the actual instance needs to be identified via environment
// and other details.
appName = "mga"
)
func main() {
var noColor bool
// rootCmd represents the base command when called without any subcommands
rootCmd := &cobra.Command{
Use: appName,
Short: "CLI tool for Modern Go Application based apps",
Version: version,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
color.NoColor = noColor
},
}
rootCmd.SetVersionTemplate(fmt.Sprintf("%s version %s (%s) built on %s\n", appName, version, commitHash, buildDate))
rootCmd.PersistentFlags().BoolVar(&noColor, "no-color", false, "Disable colorized output")
commands.AddCommands(rootCmd)
if err := rootCmd.Execute(); err != nil {
rootCmd.PrintErrln(color.RedString(err.Error()))
os.Exit(1)
}
}