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
|
|
|
|
|
|
|
|
// Ui is the cli.Ui used for communicating to the outside world.
|
|
|
|
var Ui cli.Ui
|
|
|
|
|
|
|
|
const ErrorPrefix = "e:"
|
|
|
|
const OutputPrefix = "o:"
|
|
|
|
|
|
|
|
func init() {
|
2014-10-27 23:31:02 -04:00
|
|
|
Ui = &cli.PrefixedUi{
|
|
|
|
AskPrefix: OutputPrefix,
|
|
|
|
OutputPrefix: OutputPrefix,
|
|
|
|
InfoPrefix: OutputPrefix,
|
|
|
|
ErrorPrefix: ErrorPrefix,
|
|
|
|
Ui: &cli.BasicUi{Writer: os.Stdout},
|
|
|
|
}
|
2014-10-27 23:21:13 -04:00
|
|
|
|
|
|
|
meta := command.Meta{
|
|
|
|
EnvConfig: &EnvConfig,
|
|
|
|
Ui: Ui,
|
|
|
|
}
|
|
|
|
|
|
|
|
Commands = map[string]cli.CommandFactory{
|
|
|
|
"build": func() (cli.Command, error) {
|
|
|
|
return &command.BuildCommand{
|
|
|
|
Meta: meta,
|
|
|
|
}, 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{
|
|
|
|
Meta: meta,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2014-10-27 23:31:02 -04:00
|
|
|
"inspect": func() (cli.Command, error) {
|
|
|
|
return &command.InspectCommand{
|
|
|
|
Meta: meta,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
|
|
|
"validate": func() (cli.Command, error) {
|
|
|
|
return &command.ValidateCommand{
|
|
|
|
Meta: meta,
|
|
|
|
}, nil
|
|
|
|
},
|
2014-10-27 23:51:34 -04:00
|
|
|
|
|
|
|
"version": func() (cli.Command, error) {
|
|
|
|
return &command.VersionCommand{
|
|
|
|
Meta: meta,
|
|
|
|
Revision: GitCommit,
|
|
|
|
Version: Version,
|
|
|
|
VersionPrerelease: VersionPrerelease,
|
|
|
|
CheckFunc: commandVersionCheck,
|
|
|
|
}, 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
|
|
|
|
}
|