packer-cn/packer/plugin/command.go

52 lines
821 B
Go
Raw Normal View History

2013-05-05 00:26:30 -04:00
package plugin
import (
"github.com/mitchellh/packer/packer"
"log"
2013-05-05 00:26:30 -04:00
)
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 {
log.Panic(p)
}
}