2014-10-27 23:21:13 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
|
|
|
|
"github.com/mitchellh/cli"
|
|
|
|
"github.com/mitchellh/packer/command"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Commands is the mapping of all the available Terraform commands.
|
|
|
|
var Commands map[string]cli.CommandFactory
|
|
|
|
|
2015-05-27 23:09:52 -04:00
|
|
|
// CommandMeta is the Meta to use for the commands. This must be written
|
|
|
|
// before the CLI is started.
|
|
|
|
var CommandMeta *command.Meta
|
2014-10-27 23:21:13 -04:00
|
|
|
|
|
|
|
const ErrorPrefix = "e:"
|
|
|
|
const OutputPrefix = "o:"
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
Commands = map[string]cli.CommandFactory{
|
|
|
|
"build": func() (cli.Command, error) {
|
|
|
|
return &command.BuildCommand{
|
2015-05-27 23:09:52 -04:00
|
|
|
Meta: *CommandMeta,
|
2014-10-27 23:21:13 -04:00
|
|
|
}, nil
|
|
|
|
},
|
2014-10-27 23:31:02 -04:00
|
|
|
|
2014-10-27 23:34:49 -04:00
|
|
|
"fix": func() (cli.Command, error) {
|
|
|
|
return &command.FixCommand{
|
2015-05-27 23:09:52 -04:00
|
|
|
Meta: *CommandMeta,
|
2014-10-27 23:34:49 -04:00
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2014-10-27 23:31:02 -04:00
|
|
|
"inspect": func() (cli.Command, error) {
|
|
|
|
return &command.InspectCommand{
|
2015-05-27 23:09:52 -04:00
|
|
|
Meta: *CommandMeta,
|
2014-10-27 23:31:02 -04:00
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2014-10-28 18:57:22 -04:00
|
|
|
"push": func() (cli.Command, error) {
|
|
|
|
return &command.PushCommand{
|
2015-05-27 23:09:52 -04:00
|
|
|
Meta: *CommandMeta,
|
2014-10-28 18:57:22 -04:00
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2014-10-27 23:31:02 -04:00
|
|
|
"validate": func() (cli.Command, error) {
|
|
|
|
return &command.ValidateCommand{
|
2015-05-27 23:09:52 -04:00
|
|
|
Meta: *CommandMeta,
|
2014-10-27 23:31:02 -04:00
|
|
|
}, nil
|
|
|
|
},
|
2014-10-27 23:51:34 -04:00
|
|
|
|
|
|
|
"version": func() (cli.Command, error) {
|
|
|
|
return &command.VersionCommand{
|
2015-05-27 23:09:52 -04:00
|
|
|
Meta: *CommandMeta,
|
2014-10-27 23:51:34 -04:00
|
|
|
Revision: GitCommit,
|
|
|
|
Version: Version,
|
|
|
|
VersionPrerelease: VersionPrerelease,
|
|
|
|
CheckFunc: commandVersionCheck,
|
|
|
|
}, nil
|
|
|
|
},
|
2015-08-17 04:26:03 -04:00
|
|
|
|
|
|
|
"plugin": func() (cli.Command, error) {
|
|
|
|
return &command.PluginCommand{
|
|
|
|
Meta: *CommandMeta,
|
|
|
|
}, nil
|
|
|
|
},
|
2014-10-27 23:21:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// makeShutdownCh creates an interrupt listener and returns a channel.
|
|
|
|
// A message will be sent on the channel for every interrupt received.
|
|
|
|
func makeShutdownCh() <-chan struct{} {
|
|
|
|
resultCh := make(chan struct{})
|
|
|
|
|
|
|
|
signalCh := make(chan os.Signal, 4)
|
|
|
|
signal.Notify(signalCh, os.Interrupt)
|
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
<-signalCh
|
|
|
|
resultCh <- struct{}{}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
return resultCh
|
|
|
|
}
|