-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathroot.go
61 lines (55 loc) · 1.61 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
package cmd
import (
"fmt"
"github.com/gopinath-langote/1build/cmd/del"
"github.com/gopinath-langote/1build/cmd/initialize"
"github.com/gopinath-langote/1build/cmd/list"
"github.com/gopinath-langote/1build/cmd/set"
"github.com/gopinath-langote/1build/cmd/unset"
configuration "github.com/gopinath-langote/1build/cmd/config"
"github.com/gopinath-langote/1build/cmd/exec"
"github.com/gopinath-langote/1build/cmd/utils"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// Cmd cobra for root level
var Cmd = &cobra.Command{
Use: "1build",
Version: "1.4.0",
Short: "Frictionless way of managing project-specific commands",
Args: cobra.MinimumNArgs(0),
PreRun: func(cmd *cobra.Command, args []string) {
_, err := configuration.LoadOneBuildConfiguration()
if err != nil {
fmt.Println(err)
utils.ExitError()
}
},
Run: func(cmd *cobra.Command, args []string) {
if len(args) < 1 {
list.Cmd.Run(cmd, args)
} else {
exec.ExecutePlan(args...)
}
},
}
// Execute entry-point for cobra app
func Execute() {
if err := Cmd.Execute(); err != nil {
fmt.Println(err)
utils.ExitError()
}
}
func init() {
Cmd.SetHelpCommand(&cobra.Command{Use: "no-help", Hidden: true})
Cmd.PersistentFlags().BoolP("quiet", "q", false,
"Hide output log of command & only show SUCCESS/FAILURE result")
Cmd.PersistentFlags().
StringP("file", "f", configuration.OneBuildConfigFileName, "The file path for 1build configuration file.")
_ = viper.BindPFlags(Cmd.PersistentFlags())
Cmd.AddCommand(list.Cmd)
Cmd.AddCommand(del.Cmd)
Cmd.AddCommand(initialize.Cmd)
Cmd.AddCommand(set.Cmd)
Cmd.AddCommand(unset.Cmd)
}