-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (51 loc) · 1.68 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
package main
import (
"fmt"
"os"
"github.com/jathu/starfig/internal/command"
"github.com/jathu/starfig/internal/logging"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
func safeExit(err error) {
if err != nil {
logrus.Error(err)
os.Exit(1)
}
}
// Populated via go build with flag: -ldflags "-X main.starfigVersion=<version>"
// This is the default.
var starfigVersion string = "dev"
func main() {
logging.SetupLogger()
logrus.Debug("starting starfig")
var rootCmd = &cobra.Command{
Use: "starfig",
Short: "Starfig is a programmatic config generator. It helps create static configs using Starlark, a deterministic Python-like language. Learn more at https://github.com/jathu/starfig.",
CompletionOptions: cobra.CompletionOptions{
HiddenDefaultCmd: true,
},
Run: func(cmd *cobra.Command, args []string) {
safeExit(cmd.Help())
},
}
var buildKeepGoing bool
buildCmd := cobra.Command{
Use: "build [targets...]",
Short: "Build config targets.",
Long: `Build config targets within the universe. The argument takes a list of build targets. The argument also allows building a whole package by using the spread operator. i.e. //... //example/...`,
Run: func(cmd *cobra.Command, args []string) {
safeExit(command.Build(args, buildKeepGoing))
},
}
buildCmd.Flags().BoolVar(&buildKeepGoing, "keep-going", false, "Continue to build as many targets as possible even if there are errors.")
rootCmd.AddCommand(&buildCmd)
rootCmd.AddCommand(&cobra.Command{
Use: "version",
Short: "Print the starfig version.",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(fmt.Sprintf("starfig-%s", starfigVersion))
},
})
safeExit(rootCmd.Execute())
}