This commit is contained in:
Mitchell Hashimoto 2014-07-03 12:01:20 -07:00
parent 9183068489
commit 0e88867052
4 changed files with 38 additions and 10 deletions

25
command/config.go Normal file
View File

@ -0,0 +1,25 @@
package command
import (
"github.com/hashicorp/terraform/terraform"
"github.com/mitchellh/cli"
)
// Config is a structure used to configure many commands with Terraform
// configurations.
type Config struct {
Hooks []terraform.Hook
Providers map[string]terraform.ResourceProviderFactory
Ui cli.Ui
}
func (c *Config) ContextOpts() *terraform.ContextOpts {
hooks := make([]terraform.Hook, len(c.Hooks)+1)
copy(hooks, c.Hooks)
hooks[len(c.Hooks)] = &UiHook{Ui: c.Ui}
return &terraform.ContextOpts{
Hooks: hooks,
Providers: c.Providers,
}
}

View File

@ -29,30 +29,30 @@ func init() {
Commands = map[string]cli.CommandFactory{
"apply": func() (cli.Command, error) {
return &command.ApplyCommand{
ShutdownCh: makeShutdownCh(),
TFConfig: &TFConfig,
Ui: Ui,
ShutdownCh: makeShutdownCh(),
ContextOpts: &ContextOpts,
Ui: Ui,
}, nil
},
"graph": func() (cli.Command, error) {
return &command.GraphCommand{
TFConfig: &TFConfig,
Ui: Ui,
ContextOpts: &ContextOpts,
Ui: Ui,
}, nil
},
"plan": func() (cli.Command, error) {
return &command.PlanCommand{
TFConfig: &TFConfig,
Ui: Ui,
ContextOpts: &ContextOpts,
Ui: Ui,
}, nil
},
"refresh": func() (cli.Command, error) {
return &command.RefreshCommand{
TFConfig: &TFConfig,
Ui: Ui,
ContextOpts: &ContextOpts,
Ui: Ui,
}, nil
},

View File

@ -23,6 +23,9 @@ type Config struct {
// can be overridden by user configurations.
var BuiltinConfig Config
// ContextOpts are the global ContextOpts we use to initialize the CLI.
var ContextOpts terraform.ContextOpts
// Put the parse flags we use for libucl in a constant so we can get
// equally behaving parsing everywhere.
const libuclParseFlags = libucl.ParserKeyLowercase

View File

@ -84,7 +84,7 @@ func wrappedMain() int {
defer plugin.CleanupClients()
// Initialize the TFConfig settings for the commands...
TFConfig.Providers = config.ProviderFactories()
ContextOpts.Providers = config.ProviderFactories()
// Get the command line args. We shortcut "--version" and "-v" to
// just show the version.