/
root.go
49 lines (39 loc) · 1.14 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
package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var cfgFile string
var rootCmd = &cobra.Command{
Use: "websocket-generator",
Short: "WebSocket Generator will create everything you need to deploy a fully functional WebSocket API",
Long: `WebSocket Generator adds the infrastructure and serverless code to your choosen directory and provides useful commands to deploying and deleting this code.
Run - websocket-generator init <projectName> - to get started
`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Please add --help to your command in order to find our what commands are avaliable to you.")
},
}
func Execute() {
cobra.CheckErr(rootCmd.Execute())
}
func init() {
cobra.OnInitialize(initConfig)
}
func initConfig() {
if cfgFile != "" {
viper.SetConfigFile(cfgFile)
} else {
home, err := os.UserHomeDir()
cobra.CheckErr(err)
viper.AddConfigPath(home)
viper.SetConfigType("yaml")
viper.SetConfigName(".websocket-generator")
}
viper.AutomaticEnv()
if err := viper.ReadInConfig(); err == nil {
fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
}
}