-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
99 lines (87 loc) · 2.88 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
_ "embed"
"fmt"
"github.com/kyokomi/emoji"
"github.com/spf13/cobra"
"go-transip-dyndns/commands"
"os"
"path/filepath"
)
var (
//ApplicationVersion Application version.
ApplicationVersion = "1.0.0"
CommitHash = ""
BuildDate = ""
verbose bool
keepRunning bool
//go:embed example.go-transip-dyndns.toml
ConfigTemplate string
)
func init() {
}
func main() {
commands.ConfigTemplate = ConfigTemplate
rootCmd := &cobra.Command{
Use: "go-transip-dyndns [-v]",
Short: "Update ip address on Transip DNS to current public ip ",
Long: "Use the current ip to update to a record in the TransIP dns.\nAllowing for easy updating when your ip changes.",
Version: ApplicationVersion,
Run: commands.Update,
}
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "verbose output")
validateCmd := &cobra.Command{
Use: "validate",
Short: "Validate the the setup",
Long: "Run validation to verify the setup is correct",
Example: "",
PersistentPreRun: commands.PreRun,
Run: commands.Validate,
}
initCmd := &cobra.Command{
Use: "init",
Short: "Write config file to disk",
Long: "Get a sample configuration file tog et started.",
Example: "",
Run: commands.Init,
}
createCmd := &cobra.Command{
Use: "create",
Short: "One time create record for updating",
Long: "Create a record for this configuration",
Example: "",
PersistentPreRun: commands.PreRun,
Run: commands.Create,
}
updateCmd := &cobra.Command{
Use: "update",
Short: "Update ip address on Transip DNS to current public ip (default command)",
Long: "Use the current ip to update to a record in the TransIP dns.\nAllowing for easy updating when your ip changes.",
Example: "",
PersistentPreRun: commands.PreRun,
Run: commands.Update,
}
updateCmd.PersistentFlags().BoolVarP(&keepRunning, "keep-alive", "k", false, "keep running continuously.")
versionCmd := &cobra.Command{
Use: "version",
Short: "Show the current version of the application",
Long: "Show the current version of this application.",
Example: "",
PersistentPreRun: commands.PreRun,
Run: func(cmd *cobra.Command, args []string) {
executableName := filepath.Base(os.Args[0])
fmt.Printf("%s: \n - Version: %s\n - Git Hash: %s\n - Build date: %s\n",
executableName, ApplicationVersion, CommitHash, BuildDate)
},
}
rootCmd.AddCommand(validateCmd)
rootCmd.AddCommand(initCmd)
rootCmd.AddCommand(createCmd)
rootCmd.AddCommand(updateCmd)
rootCmd.AddCommand(versionCmd)
err := rootCmd.Execute() // nolint: errcheck
if err != nil {
emoji.Printf(":exclamation: Could not execute root command!")
os.Exit(1)
}
}