github.com/kikitux/packer@v0.10.1-0.20160322154024-6237df566f9f/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 // CommandMeta is the Meta to use for the commands. This must be written 15 // before the CLI is started. 16 var CommandMeta *command.Meta 17 18 const ErrorPrefix = "e:" 19 const OutputPrefix = "o:" 20 21 func init() { 22 Commands = map[string]cli.CommandFactory{ 23 "build": func() (cli.Command, error) { 24 return &command.BuildCommand{ 25 Meta: *CommandMeta, 26 }, nil 27 }, 28 29 "fix": func() (cli.Command, error) { 30 return &command.FixCommand{ 31 Meta: *CommandMeta, 32 }, nil 33 }, 34 35 "inspect": func() (cli.Command, error) { 36 return &command.InspectCommand{ 37 Meta: *CommandMeta, 38 }, nil 39 }, 40 41 "push": func() (cli.Command, error) { 42 return &command.PushCommand{ 43 Meta: *CommandMeta, 44 }, nil 45 }, 46 47 "validate": func() (cli.Command, error) { 48 return &command.ValidateCommand{ 49 Meta: *CommandMeta, 50 }, nil 51 }, 52 53 "version": func() (cli.Command, error) { 54 return &command.VersionCommand{ 55 Meta: *CommandMeta, 56 Revision: GitCommit, 57 Version: Version, 58 VersionPrerelease: VersionPrerelease, 59 CheckFunc: commandVersionCheck, 60 }, nil 61 }, 62 63 "plugin": func() (cli.Command, error) { 64 return &command.PluginCommand{ 65 Meta: *CommandMeta, 66 }, nil 67 }, 68 } 69 } 70 71 // makeShutdownCh creates an interrupt listener and returns a channel. 72 // A message will be sent on the channel for every interrupt received. 73 func makeShutdownCh() <-chan struct{} { 74 resultCh := make(chan struct{}) 75 76 signalCh := make(chan os.Signal, 4) 77 signal.Notify(signalCh, os.Interrupt) 78 go func() { 79 for { 80 <-signalCh 81 resultCh <- struct{}{} 82 } 83 }() 84 85 return resultCh 86 }