2121 ErrNoMachineSpecified = errors .New ("Error: Expected to get one or more machine names as arguments" )
2222 ErrExpectedOneMachine = errors .New ("Error: Expected one machine name as an argument" )
2323 ErrTooManyArguments = errors .New ("Error: Too many arguments given" )
24+
25+ osExit = func (code int ) { os .Exit (code ) }
2426)
2527
2628// CommandLine contains all the information passed to the commands on the command line.
@@ -92,7 +94,7 @@ func runAction(actionName string, c CommandLine, api libmachine.API) error {
9294 return nil
9395}
9496
95- func fatalOnError (command func (commandLine CommandLine , api libmachine.API ) error ) func (context * cli.Context ) {
97+ func runCommand (command func (commandLine CommandLine , api libmachine.API ) error ) func (context * cli.Context ) {
9698 return func (context * cli.Context ) {
9799 api := libmachine .NewClient (mcndirs .GetBaseDir (), mcndirs .GetMachineCertDir ())
98100 defer api .Close ()
@@ -113,12 +115,14 @@ func fatalOnError(command func(commandLine CommandLine, api libmachine.API) erro
113115 ssh .SetDefaultClient (api .SSHClientType )
114116
115117 if err := command (& contextCommandLine {context }, api ); err != nil {
116- log .Fatal (err )
118+ log .Error (err )
117119
118120 if crashErr , ok := err .(crashreport.CrashError ); ok {
119121 crashReporter := crashreport .NewCrashReporter (mcndirs .GetBaseDir (), context .GlobalString ("bugsnag-api-token" ))
120122 crashReporter .Send (crashErr )
121123 }
124+
125+ osExit (1 )
122126 }
123127 }
124128}
@@ -140,13 +144,13 @@ var Commands = []cli.Command{
140144 {
141145 Name : "active" ,
142146 Usage : "Print which machine is active" ,
143- Action : fatalOnError (cmdActive ),
147+ Action : runCommand (cmdActive ),
144148 },
145149 {
146150 Name : "config" ,
147151 Usage : "Print the connection config for machine" ,
148152 Description : "Argument is a machine name." ,
149- Action : fatalOnError (cmdConfig ),
153+ Action : runCommand (cmdConfig ),
150154 Flags : []cli.Flag {
151155 cli.BoolFlag {
152156 Name : "swarm" ,
@@ -159,14 +163,14 @@ var Commands = []cli.Command{
159163 Name : "create" ,
160164 Usage : "Create a machine" ,
161165 Description : fmt .Sprintf ("Run '%s create --driver name' to include the create flags for that driver in the help text." , os .Args [0 ]),
162- Action : fatalOnError (cmdCreateOuter ),
166+ Action : runCommand (cmdCreateOuter ),
163167 SkipFlagParsing : true ,
164168 },
165169 {
166170 Name : "env" ,
167171 Usage : "Display the commands to set up the environment for the Docker client" ,
168172 Description : "Argument is a machine name." ,
169- Action : fatalOnError (cmdEnv ),
173+ Action : runCommand (cmdEnv ),
170174 Flags : []cli.Flag {
171175 cli.BoolFlag {
172176 Name : "swarm" ,
@@ -190,7 +194,7 @@ var Commands = []cli.Command{
190194 Name : "inspect" ,
191195 Usage : "Inspect information about a machine" ,
192196 Description : "Argument is a machine name." ,
193- Action : fatalOnError (cmdInspect ),
197+ Action : runCommand (cmdInspect ),
194198 Flags : []cli.Flag {
195199 cli.StringFlag {
196200 Name : "format, f" ,
@@ -203,18 +207,18 @@ var Commands = []cli.Command{
203207 Name : "ip" ,
204208 Usage : "Get the IP address of a machine" ,
205209 Description : "Argument(s) are one or more machine names." ,
206- Action : fatalOnError (cmdIP ),
210+ Action : runCommand (cmdIP ),
207211 },
208212 {
209213 Name : "kill" ,
210214 Usage : "Kill a machine" ,
211215 Description : "Argument(s) are one or more machine names." ,
212- Action : fatalOnError (cmdKill ),
216+ Action : runCommand (cmdKill ),
213217 },
214218 {
215219 Name : "ls" ,
216220 Usage : "List machines" ,
217- Action : fatalOnError (cmdLs ),
221+ Action : runCommand (cmdLs ),
218222 Flags : []cli.Flag {
219223 cli.BoolFlag {
220224 Name : "quiet, q" ,
@@ -240,7 +244,7 @@ var Commands = []cli.Command{
240244 Name : "regenerate-certs" ,
241245 Usage : "Regenerate TLS Certificates for a machine" ,
242246 Description : "Argument(s) are one or more machine names." ,
243- Action : fatalOnError (cmdRegenerateCerts ),
247+ Action : runCommand (cmdRegenerateCerts ),
244248 Flags : []cli.Flag {
245249 cli.BoolFlag {
246250 Name : "force, f" ,
@@ -252,7 +256,7 @@ var Commands = []cli.Command{
252256 Name : "restart" ,
253257 Usage : "Restart a machine" ,
254258 Description : "Argument(s) are one or more machine names." ,
255- Action : fatalOnError (cmdRestart ),
259+ Action : runCommand (cmdRestart ),
256260 },
257261 {
258262 Flags : []cli.Flag {
@@ -268,20 +272,20 @@ var Commands = []cli.Command{
268272 Name : "rm" ,
269273 Usage : "Remove a machine" ,
270274 Description : "Argument(s) are one or more machine names." ,
271- Action : fatalOnError (cmdRm ),
275+ Action : runCommand (cmdRm ),
272276 },
273277 {
274278 Name : "ssh" ,
275279 Usage : "Log into or run a command on a machine with SSH." ,
276280 Description : "Arguments are [machine-name] [command]" ,
277- Action : fatalOnError (cmdSSH ),
281+ Action : runCommand (cmdSSH ),
278282 SkipFlagParsing : true ,
279283 },
280284 {
281285 Name : "scp" ,
282286 Usage : "Copy files between machines" ,
283287 Description : "Arguments are [machine:][path] [machine:][path]." ,
284- Action : fatalOnError (cmdScp ),
288+ Action : runCommand (cmdScp ),
285289 Flags : []cli.Flag {
286290 cli.BoolFlag {
287291 Name : "recursive, r" ,
@@ -293,36 +297,36 @@ var Commands = []cli.Command{
293297 Name : "start" ,
294298 Usage : "Start a machine" ,
295299 Description : "Argument(s) are one or more machine names." ,
296- Action : fatalOnError (cmdStart ),
300+ Action : runCommand (cmdStart ),
297301 },
298302 {
299303 Name : "status" ,
300304 Usage : "Get the status of a machine" ,
301305 Description : "Argument is a machine name." ,
302- Action : fatalOnError (cmdStatus ),
306+ Action : runCommand (cmdStatus ),
303307 },
304308 {
305309 Name : "stop" ,
306310 Usage : "Stop a machine" ,
307311 Description : "Argument(s) are one or more machine names." ,
308- Action : fatalOnError (cmdStop ),
312+ Action : runCommand (cmdStop ),
309313 },
310314 {
311315 Name : "upgrade" ,
312316 Usage : "Upgrade a machine to the latest version of Docker" ,
313317 Description : "Argument(s) are one or more machine names." ,
314- Action : fatalOnError (cmdUpgrade ),
318+ Action : runCommand (cmdUpgrade ),
315319 },
316320 {
317321 Name : "url" ,
318322 Usage : "Get the URL of a machine" ,
319323 Description : "Argument is a machine name." ,
320- Action : fatalOnError (cmdURL ),
324+ Action : runCommand (cmdURL ),
321325 },
322326 {
323327 Name : "version" ,
324328 Usage : "Show the Docker Machine version or a machine docker version" ,
325- Action : fatalOnError (cmdVersion ),
329+ Action : runCommand (cmdVersion ),
326330 },
327331}
328332
0 commit comments