github.com/daniellockard/packer@v0.7.6-0.20141210173435-5a9390934716/commands.go (about) 1 package main 2 3 import ( 4 "os" 5 "os/signal" 6 7 "github.com/mitchellh/cli" 8 "github.com/mitchellh/packer/command" 9 ) 10 11 // Commands is the mapping of all the available Terraform commands. 12 var Commands map[string]cli.CommandFactory 13 14 // Ui is the cli.Ui used for communicating to the outside world. 15 var Ui cli.Ui 16 17 const ErrorPrefix = "e:" 18 const OutputPrefix = "o:" 19 20 func init() { 21 Ui = &cli.PrefixedUi{ 22 AskPrefix: OutputPrefix, 23 OutputPrefix: OutputPrefix, 24 InfoPrefix: OutputPrefix, 25 ErrorPrefix: ErrorPrefix, 26 Ui: &cli.BasicUi{Writer: os.Stdout}, 27 } 28 29 meta := command.Meta{ 30 EnvConfig: &EnvConfig, 31 Ui: Ui, 32 } 33 34 Commands = map[string]cli.CommandFactory{ 35 "build": func() (cli.Command, error) { 36 return &command.BuildCommand{ 37 Meta: meta, 38 }, nil 39 }, 40 41 "fix": func() (cli.Command, error) { 42 return &command.FixCommand{ 43 Meta: meta, 44 }, nil 45 }, 46 47 "inspect": func() (cli.Command, error) { 48 return &command.InspectCommand{ 49 Meta: meta, 50 }, nil 51 }, 52 53 "push": func() (cli.Command, error) { 54 return &command.PushCommand{ 55 Meta: meta, 56 }, nil 57 }, 58 59 "validate": func() (cli.Command, error) { 60 return &command.ValidateCommand{ 61 Meta: meta, 62 }, nil 63 }, 64 65 "version": func() (cli.Command, error) { 66 return &command.VersionCommand{ 67 Meta: meta, 68 Revision: GitCommit, 69 Version: Version, 70 VersionPrerelease: VersionPrerelease, 71 CheckFunc: commandVersionCheck, 72 }, nil 73 }, 74 } 75 } 76 77 // makeShutdownCh creates an interrupt listener and returns a channel. 78 // A message will be sent on the channel for every interrupt received. 79 func makeShutdownCh() <-chan struct{} { 80 resultCh := make(chan struct{}) 81 82 signalCh := make(chan os.Signal, 4) 83 signal.Notify(signalCh, os.Interrupt) 84 go func() { 85 for { 86 <-signalCh 87 resultCh <- struct{}{} 88 } 89 }() 90 91 return resultCh 92 }