Ejemplo n.º 1
0
func (m *migrateCmd) run(e *parsecli.Env) error {
	c, err := parsecli.ConfigFromDir(e.Root)
	if err != nil {
		return err
	}

	c, err = m.upgradeLegacy(e, c)
	if err != nil {
		return err
	}
	localErr := parsecli.StoreConfig(e, c)
	projectErr := parsecli.StoreProjectConfig(e, c)
	if localErr == nil && projectErr == nil {
		legacy := filepath.Join(e.Root, parsecli.LegacyConfigFile)
		err := os.Remove(legacy)
		if err != nil {
			fmt.Fprintf(e.Err, "Could not delete: %q. Please remove this file manually.\n", legacy)
		}
	} else {
		local := filepath.Join(e.Root, parsecli.ParseLocal)
		err := os.Remove(local)
		if err != nil {
			fmt.Fprintf(e.Err, "Failed to clean up: %q. Please remove this file manually.\n", local)
		}
		project := filepath.Join(e.Root, parsecli.ParseProject)
		err = os.Remove(project)
		if err != nil {
			fmt.Fprintf(e.Err, "Failed to clean up: %q. Please remove this file manually.\n", project)
		}
	}
	fmt.Fprintln(e.Out, "Successfully migrated to the preferred config format.")
	return nil
}
Ejemplo n.º 2
0
func (j *jsSDKCmd) setVersion(e *parsecli.Env, c *parsecli.Context) error {
	allVersions, err := j.getAllJSSdks(e)
	if err != nil {
		return err
	}
	valid := false
	for _, version := range allVersions {
		if version == j.newVersion {
			valid = true
		}
	}
	if !valid {
		return stackerr.New("Invalid SDK version selected.")
	}

	conf, err := parsecli.ConfigFromDir(e.Root)
	if err != nil {
		return err
	}
	conf.GetProjectConfig().Parse.JSSDK = j.newVersion
	if err := parsecli.StoreProjectConfig(e, conf); err != nil {
		return err
	}

	fmt.Fprintf(e.Out, "Current JavaScript SDK version is %s\n", conf.GetProjectConfig().Parse.JSSDK)
	return nil
}
Ejemplo n.º 3
0
// useLatestJSSDK is a utility method used by deploy & develop
// to write set jssdk version to latest available, if none set
func UseLatestJSSDK(e *parsecli.Env) error {
	var j jsSDKCmd
	versions, err := j.getAllJSSdks(e)
	if err != nil {
		return err
	}

	if len(versions) == 0 {
		return stackerr.New("No JavaScript SDK version is available.")
	}

	config, err := parsecli.ConfigFromDir(e.Root)
	if err != nil {
		return err
	}

	config.GetProjectConfig().Parse.JSSDK = versions[0]
	return parsecli.StoreProjectConfig(e, config)
}
Ejemplo n.º 4
0
func (d *deployCmd) run(e *parsecli.Env, c *parsecli.Context) error {
	var prevErr error
	for i := 0; i < d.Retries; i++ {
		parseVersion := c.Config.GetProjectConfig().Parse.JSSDK
		newDeployInfo, err := d.deploy(parseVersion, nil, false, e)
		if err == nil {
			if parseVersion == "" && newDeployInfo != nil && newDeployInfo.ParseVersion != "" {
				c.Config.GetProjectConfig().Parse.JSSDK = newDeployInfo.ParseVersion
				return parsecli.StoreProjectConfig(e, c.Config)
			}
			return nil
		}
		if err := d.handleError(i, err, prevErr, e); err != nil {
			return err
		}
		prevErr = err
	}

	return nil
}
Ejemplo n.º 5
0
func (c *configureCmd) projectType(e *parsecli.Env, args []string) error {
	config, err := parsecli.ConfigFromDir(e.Root)
	if err != nil {
		return err
	}
	if len(args) > 1 {
		return stackerr.Newf("Invalid args: %v, only an optional project type argument is expected.", args)
	}
	validTypes := map[string]int{"parse": parsecli.ParseFormat}
	invertedTypes := map[int]string{parsecli.ParseFormat: "parse"}
	numKeys := len(validTypes)
	var validKeys []string
	for key := range validTypes {
		validKeys = append(validKeys, key)
	}
	sort.Strings(validKeys)
	var selectionString string
	for n, key := range validKeys {
		selectionString += fmt.Sprintf("%d: %s\n", 1+n, key)
	}

	selectedProjectType := -1
	if len(args) != 0 {
		projectType, ok := validTypes[args[0]]
		if !ok {
			return stackerr.Newf("Invalid projectType: %v, valid types are: \n%s", selectionString)
		}
		selectedProjectType = projectType
	}

	for i := 0; i < 3; i++ {
		fmt.Fprintf(e.Out, `Select from the listed project types:
%s
Enter a number between 1 and %d: `,
			selectionString,
			numKeys,
		)
		var selection string
		fmt.Fscanf(e.In, "%s\n", &selection)
		num, err := strconv.Atoi(selection)
		if err != nil || num < 1 || num > numKeys {
			fmt.Fprintf(e.Err, "Invalid selection. Please enter a number between 1 and %d\n", numKeys)
			continue
		}
		projectType, ok := validTypes[validKeys[num-1]]
		if !ok {
			return stackerr.Newf("Invalid projectType: %v, valid types are: \n%s", selectionString)
		}
		selectedProjectType = projectType
		break
	}
	if selectedProjectType == -1 {
		return stackerr.Newf("Could not make a selection. Please try again.")
	}

	config.GetProjectConfig().Type = selectedProjectType
	if err := parsecli.StoreProjectConfig(e, config); err != nil {
		fmt.Fprintln(e.Err, "Could not save selected project type to project config")
		return err
	}
	fmt.Fprintf(e.Out, "Successfully set project type to: %v\n", invertedTypes[selectedProjectType])
	return nil
}