Skip to content

Commit

Permalink
Create 'rig ssh' command (#159)
Browse files Browse the repository at this point in the history
* 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
dnmurray authored and febbraro committed Mar 7, 2018
1 parent 9bca3aa commit a71f815
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/main.go
Expand Up @@ -66,6 +66,7 @@ func main() {
app.Commands = append(app.Commands, (&commands.Project{}).Commands()...)
app.Commands = append(app.Commands, (&commands.Doctor{}).Commands()...)
app.Commands = append(app.Commands, (&commands.Dev{}).Commands()...)
app.Commands = append(app.Commands, (&commands.SSH{}).Commands()...)

app.Run(os.Args)
}
40 changes: 40 additions & 0 deletions commands/ssh.go
@@ -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("")
}

0 comments on commit a71f815

Please sign in to comment.