18
18
package cmdconstructor
19
19
20
20
import (
21
- "fmt"
22
- "path/filepath"
23
-
24
- "github.com/elastic/cloud-sdk-go/pkg/api/platformapi/constructorapi"
25
21
"github.com/spf13/cobra"
26
22
27
23
cmdutil "github.com/elastic/ecctl/cmd/util"
28
- "github.com/elastic/ecctl/pkg/ecctl"
29
24
)
30
25
31
26
const (
32
- constructorListMessage = `Returns all of the constructors in the platform`
33
27
constructorShowMessage = `Returns information about the constructor with given ID`
34
28
constructorMaintenanceMessage = `Sets/un-sets a constructor's maintenance mode`
35
29
)
@@ -38,76 +32,8 @@ const (
38
32
var Command = & cobra.Command {
39
33
Use : "constructor" ,
40
34
Short : cmdutil .AdminReqDescription ("Manages constructors" ),
41
- PreRunE : cobra .MaximumNArgs ( 0 ) ,
35
+ PreRunE : cobra .NoArgs ,
42
36
Run : func (cmd * cobra.Command , args []string ) {
43
37
cmd .Help ()
44
38
},
45
39
}
46
-
47
- func listConstructors (cmd * cobra.Command , args []string ) error {
48
- a , err := constructorapi .List (constructorapi.Params {
49
- API : ecctl .Get ().API ,
50
- })
51
- if err != nil {
52
- return err
53
- }
54
-
55
- return ecctl .Get ().Formatter .Format (filepath .Join ("constructor" , "list" ), a )
56
- }
57
-
58
- var showConstructorCmd = & cobra.Command {
59
- Use : "show <constructor id>" ,
60
- Short : constructorShowMessage ,
61
- PreRunE : cobra .MinimumNArgs (1 ),
62
- RunE : func (cmd * cobra.Command , args []string ) error {
63
- a , err := constructorapi .Get (constructorapi.GetParams {
64
- Params : constructorapi.Params {
65
- API : ecctl .Get ().API ,
66
- },
67
- ID : args [0 ],
68
- })
69
- if err != nil {
70
- return err
71
- }
72
- return ecctl .Get ().Formatter .Format (filepath .Join ("constructor" , "show" ), a )
73
- },
74
- }
75
-
76
- var maintenanceConstructorCmd = & cobra.Command {
77
- Use : "maintenance <constructor id>" ,
78
- Short : constructorMaintenanceMessage ,
79
- PreRunE : cobra .MinimumNArgs (1 ),
80
-
81
- RunE : func (cmd * cobra.Command , args []string ) error {
82
- unset , _ := cmd .Flags ().GetBool ("unset" )
83
- fmt .Printf ("Setting contructor %s maintenance to %t\n " , args [0 ], ! unset )
84
- var params = constructorapi.MaintenanceParams {
85
- Params : constructorapi.Params {
86
- API : ecctl .Get ().API ,
87
- },
88
- ID : args [0 ],
89
- }
90
-
91
- if unset {
92
- return constructorapi .DisableMaintenance (params )
93
- }
94
- return constructorapi .EnableMaintenace (params )
95
- },
96
- }
97
-
98
- var listConstructorsCmd = & cobra.Command {
99
- Use : "list" ,
100
- Short : constructorListMessage ,
101
- PreRunE : cobra .MaximumNArgs (0 ),
102
- RunE : listConstructors ,
103
- }
104
-
105
- func init () {
106
- Command .AddCommand (
107
- listConstructorsCmd ,
108
- showConstructorCmd ,
109
- maintenanceConstructorCmd ,
110
- )
111
-
112
- maintenanceConstructorCmd .Flags ().Bool ("unset" , false , "Unset constructor maintenance mode" )
113
- }
0 commit comments