add debug mode. (#92)

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2017-08-01 16:54:34 +08:00 committed by GitHub
parent 4e625fa760
commit ed83305de8
3 changed files with 18 additions and 1 deletions

View File

@ -125,6 +125,11 @@ func main() {
Usage: "Pass envs",
EnvVar: "PLUGIN_ENVS",
},
cli.BoolFlag{
Name: "debug",
Usage: "debug mode",
EnvVar: "PLUGIN_DEBUG",
},
}
// Override a template
@ -181,6 +186,7 @@ func run(c *cli.Context) error {
Script: c.StringSlice("script"),
Secrets: c.StringSlice("secrets"),
Envs: c.StringSlice("envs"),
Debug: c.Bool("debug"),
Proxy: easyssh.DefaultConfig{
Key: c.String("proxy.ssh-key"),
KeyPath: c.String("proxy.key-path"),

View File

@ -33,6 +33,7 @@ type (
Secrets []string
Envs []string
Proxy easyssh.DefaultConfig
Debug bool
}
// Plugin structure
@ -89,6 +90,10 @@ func (p Plugin) Exec() error {
},
}
p.log(host, "======CMD======")
p.log(host, strings.Join(p.Config.Script, "\n"))
p.log(host, "======END======")
env := []string{}
for _, key := range p.Config.Envs {
key = strings.ToUpper(key)
@ -99,7 +104,12 @@ func (p Plugin) Exec() error {
p.Config.Script = append(env, p.Config.Script...)
p.log(host, "commands: ", strings.Join(p.Config.Script, "\n"))
if p.Config.Debug {
p.log(host, "======ENV======")
p.log(host, strings.Join(env, "\n"))
p.log(host, "======END======")
}
stdoutChan, stderrChan, doneChan, errChan, err := ssh.Stream(strings.Join(p.Config.Script, "\n"), p.Config.CommandTimeout)
if err != nil {
errChannel <- err

View File

@ -241,6 +241,7 @@ func TestSetENV(t *testing.T) {
KeyPath: "./tests/.ssh/id_rsa",
Secrets: []string{"FOO"},
Envs: []string{"FOO"},
Debug: true,
Script: []string{"whoami; echo $FOO"},
CommandTimeout: 1,
Proxy: easyssh.DefaultConfig{