github.com/askholme/packer@v0.7.2-0.20140924152349-70d9566a6852/packer/plugin/command.go (about) 1 package plugin 2 3 import ( 4 "github.com/mitchellh/packer/packer" 5 "log" 6 ) 7 8 type cmdCommand struct { 9 command packer.Command 10 client *Client 11 } 12 13 func (c *cmdCommand) Help() (result string) { 14 defer func() { 15 r := recover() 16 c.checkExit(r, func() { result = "" }) 17 }() 18 19 result = c.command.Help() 20 return 21 } 22 23 func (c *cmdCommand) Run(e packer.Environment, args []string) (exitCode int) { 24 defer func() { 25 r := recover() 26 c.checkExit(r, func() { exitCode = 1 }) 27 }() 28 29 exitCode = c.command.Run(e, args) 30 return 31 } 32 33 func (c *cmdCommand) Synopsis() (result string) { 34 defer func() { 35 r := recover() 36 c.checkExit(r, func() { 37 result = "" 38 }) 39 }() 40 41 result = c.command.Synopsis() 42 return 43 } 44 45 func (c *cmdCommand) checkExit(p interface{}, cb func()) { 46 if c.client.Exited() { 47 cb() 48 } else if p != nil && !Killed { 49 log.Panic(p) 50 } 51 }