@@ -2,10 +2,14 @@ package client
22
33import (
44 "errors"
5+ "fmt"
6+ "os"
57
68 "github.com/deis/deis/deisctl/backend"
79 "github.com/deis/deis/deisctl/backend/fleet"
810 "github.com/deis/deis/deisctl/cmd"
11+
12+ docopt "github.com/docopt/docopt-go"
913)
1014
1115// DeisCtlClient manages Deis components, configuration, and related tasks.
@@ -57,62 +61,247 @@ func NewClient(requestedBackend string) (*Client, error) {
5761// at /deis/<component>/<config>. Configuration values are typically used for component-level
5862// configuration, such as enabling TLS for the routers.
5963func (c * Client ) Config (argv []string ) error {
60- return cmd .Config (argv )
64+ usage := `Gets or sets a configuration value from the cluster.
65+
66+ A configuration value is stored and retrieved from a key/value store
67+ (in this case, etcd) at /deis/<component>/<config>. Configuration
68+ values are typically used for component-level configuration, such as
69+ enabling TLS for the routers.
70+
71+ Note: "deisctl config platform set sshPrivateKey=" expects a path
72+ to a private key.
73+
74+ Usage:
75+ deisctl config <target> get [<key>...]
76+ deisctl config <target> set <key=val>...
77+ deisctl config <target> rm [<key>...]
78+
79+ Examples:
80+ deisctl config platform set domain=mydomain.com
81+ deisctl config platform set sshPrivateKey=$HOME/.ssh/deis
82+ deisctl config controller get webEnabled
83+ deisctl config controller rm webEnabled
84+ `
85+ // parse command-line arguments
86+ args , err := docopt .Parse (usage , argv , true , "" , false )
87+ if err != nil {
88+ return err
89+ }
90+
91+ var action string
92+ var key []string
93+
94+ if args ["set" ] == true {
95+ action = "set"
96+ key = args ["<key=val>" ].([]string )
97+ } else if args ["rm" ] == true {
98+ action = "rm"
99+ key = args ["<key>" ].([]string )
100+ } else {
101+ action = "get"
102+ key = args ["<key>" ].([]string )
103+ }
104+
105+ return cmd .Config (args ["<target>" ].(string ), action , key )
61106}
62107
63108// Install loads the definitions of components from local unit files.
64109// After Install, the components will be available to Start.
65110func (c * Client ) Install (argv []string ) error {
66- return cmd .Install (argv , c .Backend )
111+ usage := `Loads the definitions of components from local unit files.
112+
113+ After install, the components will be available to start.
114+
115+ "deisctl install" looks for unit files in these directories, in this order:
116+ - the $DEISCTL_UNITS environment variable, if set
117+ - $HOME/.deis/units
118+ - /var/lib/deis/units
119+
120+ Usage:
121+ deisctl install [<target>...] [options]
122+ `
123+ // parse command-line arguments
124+ args , err := docopt .Parse (usage , argv , true , "" , false )
125+ if err != nil {
126+ return err
127+ }
128+
129+ return cmd .Install (args ["<target>" ].([]string ), c .Backend )
67130}
68131
69132// Journal prints log output for the specified components.
70133func (c * Client ) Journal (argv []string ) error {
71- return cmd .Journal (argv , c .Backend )
134+ usage := `Prints log output for the specified components.
135+
136+ Usage:
137+ deisctl journal [<target>...] [options]
138+ `
139+ // parse command-line arguments
140+ args , err := docopt .Parse (usage , argv , true , "" , false )
141+ if err != nil {
142+ return err
143+ }
144+
145+ return cmd .Journal (args ["<target>" ].([]string ), c .Backend )
72146}
73147
74148// List prints a summary of installed components.
75149func (c * Client ) List (argv []string ) error {
76- return cmd .ListUnits (argv , c .Backend )
150+ usage := `Prints a list of installed units.
151+
152+ Usage:
153+ deisctl list [options]
154+ `
155+ // parse command-line arguments
156+ if _ , err := docopt .Parse (usage , argv , true , "" , false ); err != nil {
157+ return err
158+ }
159+ return cmd .ListUnits (c .Backend )
77160}
78161
79162// RefreshUnits overwrites local unit files with those requested.
80163func (c * Client ) RefreshUnits (argv []string ) error {
81- return cmd .RefreshUnits (argv )
164+ usage := `Overwrites local unit files with those requested.
165+
166+ Downloading from the Deis project GitHub URL by tag or SHA is the only mechanism
167+ currently supported.
168+
169+ "deisctl install" looks for unit files in these directories, in this order:
170+ - the $DEISCTL_UNITS environment variable, if set
171+ - $HOME/.deis/units
172+ - /var/lib/deis/units
173+
174+ Usage:
175+ deisctl refresh-units [-p <target>] [-t <tag>]
176+
177+ Options:
178+ -p --path=<target> where to save unit files [default: $HOME/.deis/units]
179+ -t --tag=<tag> git tag, branch, or SHA to use when downloading unit files
180+ [default: master]
181+ `
182+ // parse command-line arguments
183+ args , err := docopt .Parse (usage , argv , true , "" , false )
184+ if err != nil {
185+ fmt .Printf ("Error: %v\n " , err )
186+ os .Exit (2 )
187+ }
188+
189+ return cmd .RefreshUnits (args ["--path" ].(string ), args ["--tag" ].(string ))
82190}
83191
84192// Restart stops and then starts components.
85193func (c * Client ) Restart (argv []string ) error {
86- return cmd .Restart (argv , c .Backend )
194+ usage := `Stops and then starts the specified components.
195+
196+ Usage:
197+ deisctl restart [<target>...] [options]
198+ `
199+ // parse command-line arguments
200+ args , err := docopt .Parse (usage , argv , true , "" , false )
201+ if err != nil {
202+ return err
203+ }
204+
205+ return cmd .Restart (args ["<target>" ].([]string ), c .Backend )
87206}
88207
89208// Scale grows or shrinks the number of running components.
90209func (c * Client ) Scale (argv []string ) error {
91- return cmd .Scale (argv , c .Backend )
210+ usage := `Grows or shrinks the number of running components.
211+
212+ Currently "router", "registry" and "store-gateway" are the only types that can be scaled.
213+
214+ Usage:
215+ deisctl scale [<target>...] [options]
216+ `
217+ // parse command-line arguments
218+ args , err := docopt .Parse (usage , argv , true , "" , false )
219+ if err != nil {
220+ return err
221+ }
222+
223+ return cmd .Scale (args ["<target>" ].([]string ), c .Backend )
92224}
93225
94226// SSH opens an interactive shell with a machine in the cluster.
95227func (c * Client ) SSH (argv []string ) error {
96- return cmd .SSH (argv , c .Backend )
228+ usage := `Open an interactive shell on a machine in the cluster given a unit or machine id.
229+
230+ Usage:
231+ deisctl ssh <target>
232+ `
233+ // parse command-line arguments
234+ args , err := docopt .Parse (usage , argv , true , "" , false )
235+ if err != nil {
236+ return err
237+ }
238+
239+ return cmd .SSH (args ["<target>" ].(string ), c .Backend )
97240}
98241
99242// Start activates the specified components.
100243func (c * Client ) Start (argv []string ) error {
101- return cmd .Start (argv , c .Backend )
244+ usage := `Activates the specified components.
245+
246+ Usage:
247+ deisctl start [<target>...] [options]
248+ `
249+ // parse command-line arguments
250+ args , err := docopt .Parse (usage , argv , true , "" , false )
251+ if err != nil {
252+ return err
253+ }
254+
255+ return cmd .Start (args ["<target>" ].([]string ), c .Backend )
102256}
103257
104258// Status prints the current status of components.
105259func (c * Client ) Status (argv []string ) error {
106- return cmd .Status (argv , c .Backend )
260+ usage := `Prints the current status of components.
261+
262+ Usage:
263+ deisctl status [<target>...] [options]
264+ `
265+ // parse command-line arguments
266+ args , err := docopt .Parse (usage , argv , true , "" , false )
267+ if err != nil {
268+ return err
269+ }
270+
271+ return cmd .Status (args ["<target>" ].([]string ), c .Backend )
107272}
108273
109274// Stop deactivates the specified components.
110275func (c * Client ) Stop (argv []string ) error {
111- return cmd .Stop (argv , c .Backend )
276+ usage := `Deactivates the specified components.
277+
278+ Usage:
279+ deisctl stop [<target>...] [options]
280+ `
281+ // parse command-line arguments
282+ args , err := docopt .Parse (usage , argv , true , "" , false )
283+ if err != nil {
284+ return err
285+ }
286+
287+ return cmd .Stop (args ["<target>" ].([]string ), c .Backend )
112288}
113289
114290// Uninstall unloads the definitions of the specified components.
115291// After Uninstall, the components will be unavailable until Install is called.
116292func (c * Client ) Uninstall (argv []string ) error {
117- return cmd .Uninstall (argv , c .Backend )
293+ usage := `Unloads the definitions of the specified components.
294+
295+ After uninstall, the components will be unavailable until install is called.
296+
297+ Usage:
298+ deisctl uninstall [<target>...] [options]
299+ `
300+ // parse command-line arguments
301+ args , err := docopt .Parse (usage , argv , true , "" , false )
302+ if err != nil {
303+ return err
304+ }
305+
306+ return cmd .Uninstall (args ["<target>" ].([]string ), c .Backend )
118307}
0 commit comments