github.com/rahart/packer@v0.12.2-0.20161229105310-282bb6ad370f/builder/hyperv/common/output_config.go (about)

     1  package common
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/mitchellh/packer/common"
     6  	"github.com/mitchellh/packer/template/interpolate"
     7  	"os"
     8  )
     9  
    10  type OutputConfig struct {
    11  	OutputDir string `mapstructure:"output_directory"`
    12  }
    13  
    14  func (c *OutputConfig) Prepare(ctx *interpolate.Context, pc *common.PackerConfig) []error {
    15  	if c.OutputDir == "" {
    16  		c.OutputDir = fmt.Sprintf("output-%s", pc.PackerBuildName)
    17  	}
    18  
    19  	var errs []error
    20  	if !pc.PackerForce {
    21  		if _, err := os.Stat(c.OutputDir); err == nil {
    22  			errs = append(errs, fmt.Errorf(
    23  				"Output directory '%s' already exists. It must not exist.", c.OutputDir))
    24  		}
    25  	}
    26  
    27  	return errs
    28  }