-
Notifications
You must be signed in to change notification settings - Fork 0
/
command_validity.go
97 lines (82 loc) · 2.18 KB
/
command_validity.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
package main
import (
"fmt"
"github.com/1and1/soma/internal/cmpl"
"github.com/1and1/soma/lib/proto"
"github.com/codegangsta/cli"
)
func registerValidity(app cli.App) *cli.App {
app.Commands = append(app.Commands,
[]cli.Command{
{
Name: "validity",
Usage: "SUBCOMMANDS for system property validity",
Subcommands: []cli.Command{
{
Name: "create",
Usage: "Create a new system property validity",
Action: runtime(cmdValidityCreate),
BashComplete: cmpl.ValidityCreate,
},
{
Name: "delete",
Usage: "Delete a system property validity",
Action: runtime(cmdValidityDelete),
},
{
Name: "list",
Usage: "List system property validity records",
Action: runtime(cmdValidityList),
},
{
Name: "show",
Usage: "Show details about a system property validity",
Action: runtime(cmdValidityShow),
},
},
},
}...,
)
return &app
}
func cmdValidityCreate(c *cli.Context) error {
utl.ValidateCliArgumentCount(c, 7)
multiple := []string{}
unique := []string{"on", "direct", "inherited"}
required := []string{"on", "direct", "inherited"}
opts := utl.ParseVariadicArguments(
multiple,
unique,
required,
c.Args().Tail())
req := proto.Request{}
req.Validity = &proto.Validity{
SystemProperty: c.Args().First(),
ObjectType: opts["on"][0],
Direct: utl.GetValidatedBool(opts["direct"][0]),
Inherited: utl.GetValidatedBool(opts["inherited"][0]),
}
resp := utl.PostRequestWithBody(Client, req, "/validity/")
fmt.Println(resp)
return nil
}
func cmdValidityDelete(c *cli.Context) error {
utl.ValidateCliArgumentCount(c, 1)
path := fmt.Sprintf("/validity/%s", c.Args().First())
resp := utl.DeleteRequest(Client, path)
fmt.Println(resp)
return nil
}
func cmdValidityList(c *cli.Context) error {
resp := utl.GetRequest(Client, "/validity/")
fmt.Println(resp)
return nil
}
func cmdValidityShow(c *cli.Context) error {
utl.ValidateCliArgumentCount(c, 1)
path := fmt.Sprintf("/validity/%s", c.Args().First())
resp := utl.GetRequest(Client, path)
fmt.Println(resp)
return nil
}
// vim: ts=4 sw=4 sts=4 noet fenc=utf-8 ffs=unix