2013-05-05 00:26:30 -04:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/mitchellh/packer/packer"
|
2013-05-08 12:46:37 -04:00
|
|
|
"log"
|
2013-05-05 00:26:30 -04:00
|
|
|
)
|
|
|
|
|
2013-05-08 13:52:23 -04:00
|
|
|
type cmdCommand struct {
|
|
|
|
command packer.Command
|
2013-06-11 14:03:36 -04:00
|
|
|
client *Client
|
2013-05-08 13:52:23 -04:00
|
|
|
}
|
|
|
|
|
2013-06-02 14:41:12 -04:00
|
|
|
func (c *cmdCommand) Help() (result string) {
|
|
|
|
defer func() {
|
|
|
|
r := recover()
|
|
|
|
c.checkExit(r, func() { result = "" })
|
|
|
|
}()
|
|
|
|
|
|
|
|
result = c.command.Help()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2013-05-08 13:52:23 -04:00
|
|
|
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()) {
|
2013-05-08 14:14:21 -04:00
|
|
|
if c.client.Exited() {
|
2013-05-08 13:52:23 -04:00
|
|
|
cb()
|
2013-08-20 02:38:22 -04:00
|
|
|
} else if p != nil && !Killed {
|
2013-05-08 14:14:21 -04:00
|
|
|
log.Panic(p)
|
2013-05-08 13:52:23 -04:00
|
|
|
}
|
|
|
|
}
|