Пример #1
0
//writeAnswers will marshal the answers map and write it to the sample file
func (b *Base) writeAnswers(sampleAnswersPath string) error {
	sampleAnswersFile, err := b.createAnswersFile(sampleAnswersPath)
	if err != nil {
		return err
	}
	data, err := yaml.Marshal(&b.AnswersData)
	if err != nil {
		logrus.Errorf("Failed to marshal answers to yaml: %s", err)
		return err
	}
	utils.WriteToFile(data, sampleAnswersFile)
	return nil
}
Пример #2
0
//SaveArtifact writes a templated artifact to the .workdir directory.
//If .workdir does not exist, it is created.
//data - a []byte of the templated file
//name - the name of the file to write to
func SaveArtifact(data []byte, targetPath, name string) error {
	workdir, err := makeWorkDirectory(targetPath)
	if err != nil {
		return err
	}

	//Create the file to write the template to
	fullPath := filepath.Join(workdir, name)
	templateFile, err := os.Create(fullPath)
	if err != nil {
		logrus.Fatalf("Unable to create template file: %s", err)
		return errors.New("Failed to create template file")
	}

	if utils.WriteToFile(data, templateFile); err != nil {
		return err
	}
	return nil
}