Extract Vagrant provider processing logic

This change extracts the provider processing logic to a separate method
which can be invoked from a subtype, providing a custom provider.
This commit is contained in:
Petr Hosek 2014-10-17 10:57:24 +01:00
parent b1c80ce44f
commit 3992f4472b
1 changed files with 18 additions and 14 deletions

View File

@ -64,20 +64,7 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
return nil
}
func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (packer.Artifact, bool, error) {
name, ok := builtins[artifact.BuilderId()]
if !ok {
return nil, false, fmt.Errorf(
"Unknown artifact type, can't build box: %s", artifact.BuilderId())
}
provider := providerForName(name)
if provider == nil {
// This shouldn't happen since we hard code all of these ourselves
panic(fmt.Sprintf("bad provider name: %s", name))
}
func (p *PostProcessor) PostProcessProvider(name string, provider Provider, ui packer.Ui, artifact packer.Artifact) (packer.Artifact, bool, error) {
config := p.configs[""]
if specificConfig, ok := p.configs[name]; ok {
config = specificConfig
@ -158,6 +145,23 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
return NewArtifact(name, outputPath), provider.KeepInputArtifact(), nil
}
func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (packer.Artifact, bool, error) {
name, ok := builtins[artifact.BuilderId()]
if !ok {
return nil, false, fmt.Errorf(
"Unknown artifact type, can't build box: %s", artifact.BuilderId())
}
provider := providerForName(name)
if provider == nil {
// This shouldn't happen since we hard code all of these ourselves
panic(fmt.Sprintf("bad provider name: %s", name))
}
return p.PostProcessProvider(name, provider, ui, artifact)
}
func (p *PostProcessor) configureSingle(config *Config, raws ...interface{}) error {
md, err := common.DecodeConfig(config, raws...)
if err != nil {