-
Notifications
You must be signed in to change notification settings - Fork 648
/
root.go
62 lines (55 loc) 路 1.47 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
62
package cmd
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"log"
"wgcf/cmd/generate"
"wgcf/cmd/register"
"wgcf/cmd/status"
"wgcf/cmd/trace"
"wgcf/cmd/update"
. "wgcf/cmd/util"
"wgcf/config"
"wgcf/util"
)
var cfgFile string
var RootCmd = &cobra.Command{
Use: "wgcf",
Short: "WireGuard Cloudflare Warp utility",
Long: FormatMessage("", `
wgcf is a utility for Cloudflare Warp that allows you to create and
manage accounts, assign license keys, and generate WireGuard profiles.
Made by Victor (@ViRb3). Project website: https://github.com/ViRb3/wgcf`),
Run: func(cmd *cobra.Command, args []string) {
if err := cmd.Help(); err != nil {
log.Fatal(util.GetErrorMessage(err))
}
},
}
func Execute() error {
return RootCmd.Execute()
}
func init() {
cobra.OnInitialize(initConfig)
RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "wgcf-account.toml", "Configuration file")
RootCmd.AddCommand(register.Cmd)
RootCmd.AddCommand(update.Cmd)
RootCmd.AddCommand(generate.Cmd)
RootCmd.AddCommand(status.Cmd)
RootCmd.AddCommand(trace.Cmd)
}
func initConfig() {
initConfigDefaults()
viper.SetConfigFile(cfgFile)
viper.SetEnvPrefix("WGCF")
viper.AutomaticEnv()
if err := viper.ReadInConfig(); err == nil {
log.Println("Using config file:", viper.ConfigFileUsed())
}
}
func initConfigDefaults() {
viper.SetDefault(config.DeviceId, "")
viper.SetDefault(config.AccessToken, "")
viper.SetDefault(config.PrivateKey, "")
viper.SetDefault(config.LicenseKey, "")
}