-
Notifications
You must be signed in to change notification settings - Fork 289
/
Copy pathstatic_funcs.go
86 lines (74 loc) · 2.12 KB
/
static_funcs.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
package hostscmd
import (
"github.com/hashicorp/boundary/api/hosts"
"github.com/hashicorp/boundary/internal/cmd/base"
)
func init() {
extraStaticActionsFlagsMapFunc = extraStaticActionsFlagsMapFuncImpl
extraStaticFlagsFunc = extraStaticFlagsFuncImpl
extraStaticFlagsHandlingFunc = extraStaticFlagsHandlingFuncImpl
}
type extraStaticCmdVars struct {
flagAddress string
}
func extraStaticActionsFlagsMapFuncImpl() map[string][]string {
return map[string][]string{
"create": {"address"},
"update": {"address"},
}
}
func (c *StaticCommand) extraStaticHelpFunc(helpMap map[string]func() string) string {
var helpStr string
switch c.Func {
case "create":
helpStr = base.WrapForHelpText([]string{
"Usage: boundary hosts create static [options] [args]",
"",
" Create a static-type host. Example:",
"",
` $ boundary hosts create static -name prodops -description "Static host for ProdOps" -address "127.0.0.1"`,
"",
"",
})
case "update":
helpStr = base.WrapForHelpText([]string{
"Usage: boundary hosts update static [options] [args]",
"",
" Update a static-type host given its ID. Example:",
"",
` $ boundary hosts update static -id hst_1234567890 -name "devops" -description "Static host for DevOps" -address "10.20.30.40"`,
"",
"",
})
default:
helpStr = helpMap[c.Func]()
}
return helpStr + c.Flags().Help()
}
func extraStaticFlagsFuncImpl(c *StaticCommand, set *base.FlagSets, _ *base.FlagSet) {
f := set.NewFlagSet("Static Host Options")
for _, name := range flagsStaticMap[c.Func] {
switch name {
case "address":
f.StringVar(&base.StringVar{
Name: "address",
Target: &c.flagAddress,
Usage: "The address of the host",
})
}
}
}
func extraStaticFlagsHandlingFuncImpl(c *StaticCommand, _ *base.FlagSets, opts *[]hosts.Option) bool {
if c.Func == "create" && c.flagAddress == "" {
c.UI.Error("Address must be provided via -address")
return false
}
switch c.flagAddress {
case "":
case "null":
*opts = append(*opts, hosts.DefaultStaticHostAddress())
default:
*opts = append(*opts, hosts.WithStaticHostAddress(c.flagAddress))
}
return true
}