This repository has been archived by the owner on Jan 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
root.go
81 lines (71 loc) · 2.77 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
package cmd
import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/starofservice/carbon/pkg/homecfg"
kubecommon "github.com/starofservice/carbon/pkg/kubernetes/common"
"github.com/starofservice/carbon/pkg/minikube"
)
var logLevel string
var rootMinikube bool
var namespace string
var RootCmd = &cobra.Command{
Use: "carbon",
Short: "Carbon is a Kubernetes package management command-line utility.",
Long: `
Carbon is a command-line utlity designed to let you to operate with your application
and related Kubernetes manifests as a signle package.
It uses standard Docker images as a foundation, but adds Kubernetes manifest templates
to Docker image lables. Hence you can use already existing Docker ecosystem in order to
distribute and store your Carbon packages.
More details can be found here: https://github.com/StarOfService/carbon`,
// Long: `Commands:
// `
// Run: func(cmd *cobra.Command, args []string) { },
PersistentPreRun: func(cmd *cobra.Command, args []string) {
log.SetFormatter(&log.TextFormatter{
FullTimestamp: true,
})
switch logLevel {
case "trace":
log.SetLevel(log.TraceLevel)
case "debug":
log.SetLevel(log.DebugLevel)
case "info":
log.SetLevel(log.InfoLevel)
case "warn":
log.SetLevel(log.WarnLevel)
case "error":
log.SetLevel(log.ErrorLevel)
case "fatal":
log.SetLevel(log.FatalLevel)
default:
log.Fatal("Unsupported log level: ", logLevel)
}
if rootMinikube {
err := minikube.CheckStatus()
if err != nil {
log.Fatalf("Failed to verify Minikube status due to the error: %s", err)
}
minikube.Enabled = true
if err := minikube.SetDockerEnv(); err != nil {
log.Fatalf("Failed to set up Docker environment variables for Minikube due to the error: %s", err)
}
}
kubecommon.SetNamespace(namespace)
err := homecfg.InitHomeConfig()
if err != nil {
log.Fatalf("Failed to initialize Carbon config directory at user home due to the error: %s", err)
}
},
}
func Execute() {
if err := RootCmd.Execute(); err != nil {
log.Fatal(err.Error())
}
}
func init() {
RootCmd.PersistentFlags().StringVarP(&logLevel, "log-level", "l", "info", "Set the logging level ('trace'|'debug'|'info'|'warn'|'error'|'fatal') (default 'info')")
RootCmd.PersistentFlags().BoolVarP(&rootMinikube, "minikube", "m", false, "Use the local Minikube instance instead of remote repositories and Kubernetes clusters. May be useful for local development process. Disabled by default.")
RootCmd.PersistentFlags().StringVarP(&namespace, "namespace", "n", "default", "If present, defineds a default Kubernetes namespace for installed resources. The behaviour of this parameter depends on the used Carbon scope")
}