This repository has been archived by the owner on Aug 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
main.go
90 lines (83 loc) · 2.12 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
package main
import (
"os"
"path/filepath"
"github.com/knadh/stuffbin"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"zerodha.tech/kubekutr/cmd"
)
var (
// Version and date of the build. This is injected at build-time.
buildVersion = "unknown"
buildDate = "unknown"
)
// initLogger initializes logger
func initLogger(verbose bool) *logrus.Logger {
logger := logrus.New()
logger.SetFormatter(&logrus.TextFormatter{
FullTimestamp: true,
})
// Set logger level
if verbose {
logger.SetLevel(logrus.DebugLevel)
logger.Debug("verbose logging enabled")
} else {
logger.SetLevel(logrus.InfoLevel)
}
return logger
}
// initFileSystem initializes the stuffbin FileSystem to provide
// access to bunded static assets to the app.
func initFileSystem(binPath string) (stuffbin.FileSystem, error) {
ex, err := os.Executable()
if err != nil {
panic(err)
}
exPath := filepath.Dir(ex)
fs, err := stuffbin.UnStuff(filepath.Join(exPath, filepath.Base(os.Args[0])))
if err != nil {
return nil, err
}
return fs, nil
}
func main() {
// Intialize new CLI app
app := cli.NewApp()
app.Name = "kubekutr"
app.Usage = "Cookie cutter for Kubernetes resource manifests"
app.Version = buildVersion
app.Author = "Karan Sharma @mrkaran"
// Register command line args.
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "verbose",
Usage: "Enable verbose logging",
},
cli.StringSliceFlag{
Name: "config, c", Value: &cli.StringSlice{}, Usage: "path to one or more config files", TakesFile: true},
}
var (
logger = initLogger(true)
)
// Initialize the static file system into which all
// required static assets (.css, .js files etc.) are loaded.
fs, err := initFileSystem(os.Args[0])
if err != nil {
logger.Errorf("error reading stuffed binary: %v", err)
os.Exit(1)
}
// Initialize hub.
hub := cmd.NewHub(logger, fs, buildVersion)
// Register commands.
app.Commands = []cli.Command{
hub.ScaffoldProject(hub.Config),
hub.InitProject(hub.Config),
}
// Run the app.
hub.Logger.Info("Starting kubekutr...")
err = app.Run(os.Args)
if err != nil {
logger.Errorf("Something terrbily went wrong: %s", err)
}
}