Example #1
0
func getAndPourSkeleton(skeleton string) error {
	// Get or update given skeleton.
	task := fmt.Sprintf("Get or update skeleton '%v'", skeleton)
	log.Run(task)
	if err := getOrUpdateSkeleton(flagSkeleton); err != nil {
		return errs.NewError(task, err)
	}

	// Move the skeleton files into place.
	task = "Copy the skeleton into the configuration directory"
	log.Go(task)

	localConfigDir, err := config.LocalConfigDirectoryAbsolutePath()
	if err != nil {
		return errs.NewError(task, err)
	}

	log.NewLine("")
	if err := pourSkeleton(flagSkeleton, localConfigDir); err != nil {
		return errs.NewError(task, err)
	}
	log.NewLine("")
	log.Ok(task)

	return nil
}
Example #2
0
func ensureLocalConfigDirectoryExists() (action.Action, error) {
	task := "Make sure the local configuration directory exists"

	// Get the directory absolute path.
	localConfigDir, err := config.LocalConfigDirectoryAbsolutePath()
	if err != nil {
		return nil, errs.NewError(task, err)
	}

	// In case the path exists, make sure it is a directory.
	info, err := os.Stat(localConfigDir)
	if err != nil {
		if !os.IsNotExist(err) {
			return nil, errs.NewError(task, err)
		}
	} else {
		if !info.IsDir() {
			return nil, errs.NewError(task, fmt.Errorf("not a directory: %v", localConfigDir))
		}
		return action.Noop, nil
	}

	// Otherwise create the directory.
	if err := os.MkdirAll(localConfigDir, 0755); err != nil {
		return nil, errs.NewError(task, err)
	}

	// Return the rollback function.
	act := action.ActionFunc(func() error {
		// Delete the directory.
		log.Rollback(task)
		task := "Delete the local configuration directory"
		if err := os.RemoveAll(localConfigDir); err != nil {
			return errs.NewError(task, err)
		}
		return nil
	})
	return act, nil
}