forked from hashicorp/packer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.go
51 lines (42 loc) · 832 Bytes
/
command.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
package plugin
import (
"github.com/mitchellh/packer/packer"
"log"
)
type cmdCommand struct {
command packer.Command
client *Client
}
func (c *cmdCommand) Help() (result string) {
defer func() {
r := recover()
c.checkExit(r, func() { result = "" })
}()
result = c.command.Help()
return
}
func (c *cmdCommand) Run(e packer.Environment, args []string) (exitCode int) {
defer func() {
r := recover()
c.checkExit(r, func() { exitCode = 1 })
}()
exitCode = c.command.Run(e, args)
return
}
func (c *cmdCommand) Synopsis() (result string) {
defer func() {
r := recover()
c.checkExit(r, func() {
result = ""
})
}()
result = c.command.Synopsis()
return
}
func (c *cmdCommand) checkExit(p interface{}, cb func()) {
if c.client.Exited() {
cb()
} else if p != nil && !Killed {
log.Panic(p)
}
}