-
Notifications
You must be signed in to change notification settings - Fork 11
/
cmd.go
104 lines (92 loc) · 1.66 KB
/
cmd.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
100
101
102
103
104
package main
import (
"os/user"
"github.com/spf13/cobra"
)
var prefix string
var sshUser string
var identityFile string
var jumphost string
var filters string
var openSubnet string
var rootCmd = &cobra.Command{
Use: "generate-ssh-configs",
Run: func(cmd *cobra.Command, args []string) {
err := cmd.Help()
checkErr(err)
},
}
var awsCmd = &cobra.Command{
Use: "aws",
Run: func(cmd *cobra.Command, args []string) {
if prefix != "" {
prefix = prefix + "-"
}
generateAWS(prefix)
},
}
var digitalOceanCmd = &cobra.Command{
Use: "digital-ocean",
Run: func(cmd *cobra.Command, args []string) {
if prefix != "" {
prefix = prefix + "-"
}
generateDigitalOcean(prefix)
},
}
func requirePrefix(cmd *cobra.Command) {
cmd.Flags().StringVar(
&prefix,
"prefix",
"",
"The prefix thats used in the ssh file for this group",
)
}
func userFlag(cmd *cobra.Command) {
cmd.Flags().StringVar(
&sshUser,
"user",
"",
"The ssh user",
)
}
func identityFileFlag(cmd *cobra.Command) {
usr, err := user.Current()
if err != nil {
panic(err)
}
defaultIdentityFile := usr.HomeDir + "/.ssh/id_rsa"
cmd.Flags().StringVar(
&identityFile,
"identityFile",
defaultIdentityFile,
"",
)
}
func cmdInit() {
requirePrefix(awsCmd)
requirePrefix(digitalOceanCmd)
userFlag(awsCmd)
userFlag(digitalOceanCmd)
identityFileFlag(awsCmd)
awsCmd.Flags().StringVar(
&jumphost,
"jumphost",
"",
"The jumphost",
)
awsCmd.Flags().StringVar(
&filters,
"filters",
"",
"AWS instance filters",
)
awsCmd.Flags().StringVar(
&openSubnet,
"subnet",
"",
"Additional open subnet",
)
rootCmd.AddCommand(awsCmd)
rootCmd.AddCommand(digitalOceanCmd)
}