// Run applies the provided arguments to the provided script template,
// and executes the resulting script via the provided Runner.
//
// N.B.: this utility function is placed here so that 1) it is hopefully easier
// to known how to run the scripts provided in this package and 2) its
// implementation can be re-used by the various parts of WKS.
Run applies the provided arguments to the provided script template,
and executes the resulting script via the provided Runner.

N.B.: this utility function is placed here so that 1) it is hopefully easier
to known how to run the scripts provided in this package and 2) its
implementation can be re-used by the various parts of WKS.
// Run applies the provided arguments to the provided script template // and executes the resulting script via the provided Runner . // // N . B . : this utility function is placed here so that 1 ) it is hopefully easier // to known how to run the scripts provided in this package and 2 ) its // implementation can be re - used by the various parts of WKS .
func Run(path string, args interface{}, runner runner) (string, error) {
	script, err := Scripts.Open(path)
	if err != nil {
		return "", err
	}
	defer script.Close()
	scriptContent, err := ioutil.ReadAll(script)
	if err != nil {
		return "", err
	}
	scriptTemplate, err := template.New(path).Parse(string(scriptContent))
	if err != nil {
		return "", err
	}
	var body bytes.Buffer
	err = scriptTemplate.Execute(&body, args)
	if err != nil {
		return "", err
	}
	stdOutErr, err := runner.RunCommand(body.String(), nil)
	if err != nil {
		log.WithFields(log.Fields{
			"stdOutErr": stdOutErr,
			"path":      path,
			"args":      args,
			"runner":    runner,
		}).Debug("failed to run script")
	}
	return stdOutErr, err
}
func Run ( path string , args interface { } , runner runner ) ( string , error ) { script , err := Scripts . Open ( path ) if err != nil { return " " , err } defer script . Close ( ) scriptContent , err := ioutil . ReadAll ( script ) if err != nil { return " " , err } scriptTemplate , err := template . New ( path ) . Parse ( string ( scriptContent ) ) if err != nil { return " " , err } var body bytes . Buffer err = scriptTemplate . Execute ( & body , args ) if err != nil { return " " , err } stdOutErr , err := runner . RunCommand ( body . String ( ) , nil ) if err != nil { log . WithFields ( log . Fields { " " : stdOutErr , " " : path , " " : args , " " : runner , } ) . Debug ( " " ) } return stdOutErr , err }
Run applies the provided arguments to the provided script template,
and executes the resulting script via the provided Runner.
Run applies the provided arguments to the provided script template and executes the resulting script via the provided Runner .