-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
81 lines (66 loc) · 2.5 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
package main
import (
"log"
"github.com/clems4ever/anytype-backup-node/internal/backupnode"
"github.com/spf13/cobra"
)
var configPathFlag string
var defaultConfigPath = "config.yml"
var rootCmd = cobra.Command{
Use: "anytype-backup-node",
Short: "Start an anytype backup node",
}
var manualCmd = cobra.Command{
Use: "manual",
Short: "Some commands that can be run manually if necessary.",
Long: "Some commands that can be run manually if you know what you are doing, otherwise let the bootstrap command handle it for you.",
}
var initCmd = cobra.Command{
Use: "init",
Short: "Generate a default configuration file that can be edited before bootstraping the infrastructure",
Run: func(cmd *cobra.Command, args []string) {
backupnode.Init()
},
}
var generateNetconfCmd = cobra.Command{
Use: "generate",
Short: "Generate the configuration of an anytype backup node",
Long: "Generate the configuration of an anytype backup node." +
"This is only useful if you want to manually generate the configuration, " +
"otherwise you can let the bootstrap command do it for you.",
Run: func(cmd *cobra.Command, args []string) {
backupnode.GenerateConfig(configPathFlag)
},
}
var bootstrapNodeCmd = cobra.Command{
Use: "bootstrap",
Short: "Bootstrap a backup node after you have generated a config file with the init command",
Long: "Bootstrap a backup node from the configuration file",
Run: func(cmd *cobra.Command, args []string) {
backupnode.Bootstrap(cmd.Context(), configPathFlag)
},
}
var configureCmd = cobra.Command{
Use: "configure",
Short: "Configure the infrastructure after it has been spawned",
Long: "Configure the infrastructure after it has been spawned. " +
"This is only useful if you have to do it manually, otherwise you can let " +
"the bootstrap command handle it for you.",
Run: func(cmd *cobra.Command, args []string) {
backupnode.Initialize(cmd.Context(), configPathFlag)
},
}
func main() {
rootCmd.AddCommand(&initCmd)
rootCmd.AddCommand(&manualCmd)
generateNetconfCmd.Flags().StringVarP(&configPathFlag, "config", "c", defaultConfigPath, "path to the config file")
manualCmd.AddCommand(&generateNetconfCmd)
bootstrapNodeCmd.Flags().StringVarP(&configPathFlag, "config", "c", defaultConfigPath, "path to the config file")
rootCmd.AddCommand(&bootstrapNodeCmd)
configureCmd.Flags().StringVarP(&configPathFlag, "config", "c", defaultConfigPath, "path to the config file")
manualCmd.AddCommand(&configureCmd)
err := rootCmd.Execute()
if err != nil {
log.Fatal(err)
}
}