Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create 'rig ssh' command * gofmt and remove flags from ssh * cleanup the ssh return values * ssh command: fix lint messages * ssh command: better message if machine does not exist
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package commands | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
|
||
"github.com/phase2/rig/util" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
// SSH is the command for staring an SSH session inside the docker machine vm | ||
type SSH struct { | ||
BaseCommand | ||
} | ||
|
||
// Commands returns the operations supported by this command | ||
func (cmd *SSH) Commands() []cli.Command { | ||
return []cli.Command{ | ||
{ | ||
Name: "ssh", | ||
Usage: "Start an ssh session into the docker-machine vm", | ||
Before: cmd.Before, | ||
Action: cmd.Run, | ||
}, | ||
} | ||
} | ||
|
||
// Run executes the `rig ssh` command | ||
func (cmd *SSH) Run(c *cli.Context) error { | ||
// Does the docker-machine exist | ||
if !cmd.machine.Exists() { | ||
return cmd.Failure(fmt.Sprintf("No machine named '%s' exists.", cmd.machine.Name), "MACHINE-NOT-FOUND", 12) | ||
} | ||
|
||
/* #nosec */ | ||
if exitCode := util.PassthruCommand(exec.Command("docker-machine", "ssh", cmd.machine.Name)); exitCode != 0 { | ||
return cmd.Failure(fmt.Sprintf("Failure running 'docker-machine ssh %s'", cmd.machine.Name), "COMMAND-ERROR", exitCode) | ||
} | ||
return cmd.Success("") | ||
} |