-
Notifications
You must be signed in to change notification settings - Fork 1
/
shell.go
72 lines (64 loc) · 1.66 KB
/
shell.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"errors"
"fmt"
"path/filepath"
"strings"
"github.com/urfave/cli"
)
// CmdShell spawns an interactive shell
func CmdShell(c *cli.Context) error {
conf, err := CurrentConfig(c)
if err != nil {
return err
}
env, err := Env(c)
if err != nil {
return err
}
dBinary := filepath.Join(c.GlobalString("dockerdir"), "docker")
cmd := []string{dBinary, "exec", "-it", conf.Container, "/bin/bash"}
return Exec(cmd, env)
}
// RunCmd runs a command in a bash shell in the docker container, replacing this process
func RunCmd(c *cli.Context, args []string) error {
conf, err := CurrentConfig(c)
if err != nil {
return err
}
env, err := Env(c)
if err != nil {
return err
}
dBinary := filepath.Join(c.GlobalString("dockerdir"), "docker")
cmd := []string{dBinary, "exec", "-it", conf.Container, "/bin/bash", "-c", strings.Join(args, " ")}
return Exec(cmd, env)
}
// CmdCommand runs a command
func CmdCommand(c *cli.Context) error {
args := c.Args()
if len(args) < 1 {
return errors.New("command requires a command to run")
}
return RunCmd(c, args)
}
// CmdWp runs wp
func CmdWp(c *cli.Context) error {
args := append([]string{"/usr/local/bin/wp"}, c.Args()...)
return RunCmd(c, args)
}
// CmdMysql runs mysql
func CmdMysql(c *cli.Context) error {
conf, err := CurrentConfig(c)
if err != nil {
return err
}
args := []string{"/usr/bin/mysql"}
args = append(args, fmt.Sprintf("--user=%s", conf.Mysql.User))
if conf.Mysql.Password != "" {
args = append(args, fmt.Sprintf("--password=%s", conf.Mysql.Password))
}
args = append(args, fmt.Sprintf("--database=%s", conf.Mysql.Database))
args = append(args, c.Args()...)
return RunCmd(c, args)
}