github.com/sneal/packer@v0.5.2/builder/virtualbox/common/export_config.go (about)

     1  package common
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  	"github.com/mitchellh/packer/packer"
     7  )
     8  
     9  type ExportConfig struct {
    10  	Format string `mapstruture:"format"`
    11  }
    12  
    13  func (c *ExportConfig) Prepare(t *packer.ConfigTemplate) []error {
    14  	if c.Format == "" {
    15  		c.Format = "ovf"
    16  	}
    17  
    18  	templates := map[string]*string{
    19  		"format": &c.Format,
    20  	}
    21  
    22  	errs := make([]error, 0)
    23  	for n, ptr := range templates {
    24  		var err error
    25  		*ptr, err = t.Process(*ptr, nil)
    26  		if err != nil {
    27  			errs = append(errs, fmt.Errorf("Error processing %s: %s", n, err))
    28  		}
    29  	}
    30  
    31  	if c.Format != "ovf" && c.Format != "ova" {
    32  		errs = append(errs,
    33  			errors.New("invalid format, only 'ovf' or 'ova' are allowed"))
    34  	}
    35  
    36  	return errs
    37  }