-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.go
More file actions
54 lines (42 loc) · 1.27 KB
/
main.go
File metadata and controls
54 lines (42 loc) · 1.27 KB
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
// Package main is the package that contains the entry point for the application.
package main
import (
"os"
"github.com/AlphaSense-Engineering/privatecloud-cli/cmd"
"github.com/AlphaSense-Engineering/privatecloud-cli/pkg/constant"
"github.com/AlphaSense-Engineering/privatecloud-cli/pkg/util"
"github.com/charmbracelet/log"
_ "github.com/go-sql-driver/mysql"
"github.com/spf13/cobra"
)
// addCommand is the function that adds a command to the root command and hooks its Run function.
func addCommand(logger *log.Logger, rootCmd *cobra.Command, cmdFn func(*log.Logger) *cobra.Command) {
cobraCmd := cmdFn(logger)
oldRun := cobraCmd.Run
cobraCmd.Run = func(cobraCmd *cobra.Command, args []string) {
if util.FlagBool(cobraCmd, cmd.FlagVerbose) {
logger.SetLevel(log.DebugLevel)
}
oldRun(cobraCmd, args)
}
rootCmd.AddCommand(cobraCmd)
}
// main is the entry point for the application.
func main() {
logger := log.NewWithOptions(os.Stderr, log.Options{
ReportTimestamp: true,
TimeFunction: constant.LogDefaultTimeFunc,
})
rootCmd := cmd.Root()
cmdFns := []func(*log.Logger) *cobra.Command{
cmd.Check,
cmd.Install,
cmd.Pod,
}
for _, cmdFn := range cmdFns {
addCommand(logger, rootCmd, cmdFn)
}
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}