-
Notifications
You must be signed in to change notification settings - Fork 23
/
root.go
90 lines (77 loc) · 2.93 KB
/
root.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
package cmd
import (
"os"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/fluxninja/aperture/cmd/aperturectl/cmd/apply"
"github.com/fluxninja/aperture/cmd/aperturectl/cmd/autoscale"
"github.com/fluxninja/aperture/cmd/aperturectl/cmd/blueprints"
"github.com/fluxninja/aperture/cmd/aperturectl/cmd/build"
"github.com/fluxninja/aperture/cmd/aperturectl/cmd/delete"
"github.com/fluxninja/aperture/cmd/aperturectl/cmd/discovery"
"github.com/fluxninja/aperture/cmd/aperturectl/cmd/flowcontrol"
"github.com/fluxninja/aperture/cmd/aperturectl/cmd/installation"
"github.com/fluxninja/aperture/cmd/aperturectl/cmd/utils"
"github.com/fluxninja/aperture/pkg/config"
"github.com/fluxninja/aperture/pkg/info"
"github.com/fluxninja/aperture/pkg/log"
)
// Version shows the version of ApertureCtl.
var (
Version = info.Version
verbose bool
)
func init() {
RootCmd.AddCommand(blueprints.BlueprintsCmd)
RootCmd.AddCommand(compileCmd)
RootCmd.AddCommand(apply.ApplyCmd)
RootCmd.AddCommand(installation.InstallCmd)
RootCmd.AddCommand(installation.UnInstallCmd)
RootCmd.AddCommand(flowcontrol.FlowControlCmd)
RootCmd.AddCommand(autoscale.AutoScaleCmd)
RootCmd.AddCommand(discovery.DiscoveryCmd)
RootCmd.AddCommand(build.BuildCmd)
RootCmd.AddCommand(agentsCmd)
RootCmd.AddCommand(delete.DeleteCmd)
RootCmd.InitDefaultCompletionCmd()
RootCmd.SilenceUsage = true
}
// RootCmd is the root command for aperturectl.
var RootCmd = &cobra.Command{
Use: "aperturectl",
Short: "aperturectl - CLI tool to interact with Aperture",
DisableAutoGenTag: true,
DisableSuggestions: false,
Long: `
aperturectl is a CLI tool which can be used to interact with Aperture seamlessly.`,
Version: Version,
}
// Execute is the entry point for the CLI. It is called from the main package.
func Execute() {
// Process the verbose and allowDeprecated flags before executing the command.
// Fun fact: PersistentPreRunE does not allow chaining.
// set flags manually using pflag and parse them
pflag.BoolVarP(&verbose, "verbose", "v", false, "Enable verbose logging")
pflag.BoolVar(&utils.AllowDeprecated, "allow-deprecated", false, "Allow deprecated fields in the configuration")
// Set help flag to false by default to print help for aperturectl command instead of pflag
pflag.BoolP("help", "h", false, "Display help for aperturectl command")
// configure pflag to ignore unknown flags
pflag.CommandLine.ParseErrorsWhitelist.UnknownFlags = true
pflag.Parse()
pflag.CommandLine.ParseErrorsWhitelist.UnknownFlags = false
level := "info"
if verbose {
level = "debug"
}
logger := log.NewLogger(log.GetPrettyConsoleWriter(), level)
log.SetGlobalLogger(logger)
err := config.RegisterDeprecatedValidator(utils.AllowDeprecated)
if err != nil {
log.Error().Err(err).Msg("Error registering deprecated validator")
os.Exit(1)
}
if err := RootCmd.Execute(); err != nil {
log.Error().Err(err).Msg("Error executing aperturectl")
os.Exit(1)
}
}