Example #1
0
func Initialize(do *definitions.Do) error {
	if _, err := os.Stat(common.ErisRoot); err != nil {
		if os.IsNotExist(err) {
			logger.Infoln("Eris Root Directory does not exist. The marmots will initialize this directory for you.\n")
			if err := common.InitErisDir(); err != nil {
				return fmt.Errorf("Error:\tcould not Initialize the Eris Root Directory.\n%s\n", err)
			}
		} else {
			panic(err)
		}
	}

	if do.Yes {
		logger.Debugf("Not requiring input. Proceeding.\n")
	} else {
		var input string
		logger.Printf("Eris Root Directory (%s) already exists.\nContinuing may overwrite files in:\n%s\n%s\nDo you wish to continue? (y/n): ", common.ErisRoot, common.ServicesPath, common.ActionsPath)
		if _, err := fmt.Scanln(&input); err != nil {
			return fmt.Errorf("Error reading from stdin: %v\n", err)
		}
		if input == "Y" || input == "y" || input == "YES" || input == "Yes" || input == "yes" {
			logger.Debugf("Confirmation verified. Proceeding.\n")
		} else {
			logger.Printf("\nThe marmots will not proceed without your permission to overwrite.\nPlease backup your files and try again.\n")
			return fmt.Errorf("Error:\tno permission given to overwrite services and actions.\n")
		}
	}

	//goes and does everything
	if err := InitDefaultServices(do); err != nil {
		return fmt.Errorf("Error:\tcould not Instantiate default services.\n%s\n", err)
	}

	var prompt bool
	if do.Yes || os.Getenv("ERIS_MIGRATE_APPROVE") == "true" {
		prompt = false
	} else {
		prompt = true
	}
	if err := util.MigrateDeprecatedDirs(common.DirsToMigrate, prompt); err != nil {
		return fmt.Errorf("Error:\tcould not migrate directories.\n%s\n", err)
	}
	return nil
}
Example #2
0
func checkIfMigrationRequired(doYes bool) error {
	if err := util.MigrateDeprecatedDirs(common.DirsToMigrate, !doYes); err != nil {
		return fmt.Errorf("Error:\tcould not migrate directories.\n%s\n", err)
	}
	return nil
}