// Configure is used to extract options and customize the summon.Driver.
Configure is used to extract options and customize the summon.Driver.
// Configure is used to extract options and customize the summon . Driver .
func (d *Driver) Configure(opts ...Option) error {
	if d == nil {
		return fmt.Errorf("driver cannot be nil")
	}
	if !d.configRead {
		config, err := d.box.Find(config.ConfigFile)
		if err == nil {
			err = d.Config.Unmarshal(config)
			if err != nil {
				return err
			}
			d.opts.DefaultsFrom(d.Config)
			d.templateCtx, err = template.New(Name).
				Option("missingkey=zero").
				Funcs(sprig.TxtFuncMap()).
				Funcs(summonFuncMap(d)).
				Parse(d.Config.TemplateContext)
			if err != nil {
				return err
			}
			d.configRead = true
		}
	}
	for _, opt := range opts {
		err := opt(&d.opts)
		if err != nil {
			return err
		}
	}
	if d.opts.destination == "" {
		d.opts.destination = config.DefaultOutputDir
	}
	if d.opts.out == nil {
		d.opts.out = os.Stdout
	}
	if d.opts.execCommand != nil {
		d.execCommand = d.opts.execCommand
	}
	return nil
}
func ( d * Driver ) Configure ( opts ... Option ) error { if d == nil { return fmt . Errorf ( " " ) } if ! d . configRead { config , err := d . box . Find ( config . ConfigFile ) if err == nil { err = d . Config . Unmarshal ( config ) if err != nil { return err } d . opts . DefaultsFrom ( d . Config ) d . templateCtx , err = template . New ( Name ) . Option ( " " ) . Funcs ( sprig . TxtFuncMap ( ) ) . Funcs ( summonFuncMap ( d ) ) . Parse ( d . Config . TemplateContext ) if err != nil { return err } d . configRead = true } } for _ , opt := range opts { err := opt ( & d . opts ) if err != nil { return err } } if d . opts . destination == " " { d . opts . destination = config . DefaultOutputDir } if d . opts . out == nil { d . opts . out = os . Stdout } if d . opts . execCommand != nil { d . execCommand = d . opts . execCommand } return nil }
Configure is used to extract options and customize the summon.Driver.
Configure is used to extract options and customize the summon . Driver .
// try to find a config file in the box