-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathroot.go
55 lines (47 loc) · 1.22 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
package cmd
import (
"fmt"
"os"
"os/exec"
"github.com/spf13/afero"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/volatiletech/abcweb/v5/config"
)
var (
cnf *config.Configuration
appFS = afero.NewOsFs()
)
// RootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Use: "abcweb",
Long: `ABCWeb is a tool to help you scaffold and develop Go web applications.`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
var err error
cnf, err = config.Initialize(nil)
if err != nil {
return err
}
return nil
},
}
// Execute adds all child commands to the root command sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
if err := RootCmd.Execute(); err != nil {
os.Exit(1)
}
}
func checkDep(names ...string) {
for _, name := range names {
_, err := exec.LookPath(name)
if err != nil {
fmt.Printf("Error: could not find %q dependency in $PATH. Please run \"abcweb deps\" to install all missing dependencies.", name)
os.Exit(1)
}
}
}
func init() {
RootCmd.Flags().BoolP("version", "", false, "Print the abcweb version")
viper.BindPFlags(RootCmd.Flags())
}