github.com/askholme/packer@v0.7.2-0.20140924152349-70d9566a6852/packer/plugin/hook.go (about) 1 package plugin 2 3 import ( 4 "github.com/mitchellh/packer/packer" 5 "log" 6 ) 7 8 type cmdHook struct { 9 hook packer.Hook 10 client *Client 11 } 12 13 func (c *cmdHook) Run(name string, ui packer.Ui, comm packer.Communicator, data interface{}) error { 14 defer func() { 15 r := recover() 16 c.checkExit(r, nil) 17 }() 18 19 return c.hook.Run(name, ui, comm, data) 20 } 21 22 func (c *cmdHook) Cancel() { 23 defer func() { 24 r := recover() 25 c.checkExit(r, nil) 26 }() 27 28 c.hook.Cancel() 29 } 30 31 func (c *cmdHook) checkExit(p interface{}, cb func()) { 32 if c.client.Exited() && cb != nil { 33 cb() 34 } else if p != nil && !Killed { 35 log.Panic(p) 36 } 37 }