Beispiel #1
0
func (a *addCmd) run(e *parsecli.Env, args []string) error {

	if err := a.apps.Login.AuthUser(e, false); err != nil {
		return err
	}
	var appName string
	if len(args) > 1 {
		return stackerr.New("Only an optional Parse app name is expected.")
	}
	if len(args) == 1 {
		appName = args[0]
	}

	app, err := a.selectApp(e, appName)
	if err != nil {
		return err
	}

	var appConfig parsecli.AppConfig
	switch e.Type {
	case parsecli.LegacyParseFormat, parsecli.ParseFormat:
		appConfig = parsecmd.GetParseAppConfig(app)

	case parsecli.HerokuFormat:
		_, appConfig, err = herokucmd.GetLinkedHerokuAppConfig(app, e)
		if err != nil {
			return err
		}
	}

	return a.addSelectedApp(app.Name, appConfig, args, e)
}
Beispiel #2
0
func (n *newCmd) run(e *parsecli.Env) error {
	apps := &parsecli.Apps{}
	addCmd := &addCmd{MakeDefault: true, apps: apps}

	if err := apps.Login.AuthUser(e, false); err != nil {
		return err
	}
	var (
		app *parsecli.App
		err error
	)

	nonInteractive := n.parseAppName != "" && n.codeLocation != ""
	decision, err := n.promptCreateNewApp(e, nonInteractive)
	if err != nil {
		return err
	}
	isNew := false

	switch decision {
	case "new", "n":
		isNew = true
		var createRetries int
		if n.noCode {
			createRetries = 1
		}
		// we pass retries so that even in non interactive mode we can create an app,
		// and failure does not print 3 times to the screen
		app, err = apps.CreateApp(e, n.parseAppName, createRetries)
		if err != nil {
			return err
		}
		if n.noCode {
			fmt.Fprintln(e.Out, "Successfully created the app.")
			return apps.PrintApp(e, app)
		}
	case "existing", "e":
		app, err = addCmd.selectApp(e, n.parseAppName)
		if err != nil {
			return err
		}
		if n.noCode {
			fmt.Fprintln(e.Out, "Successfully selected the app.")
			return apps.PrintApp(e, app)
		}
	}

	projectType, err := herokucmd.PromptCreateWebhooks(e)
	if err != nil {
		return err
	}

	var appConfig parsecli.AppConfig
	switch projectType {
	case "heroku":
		e.Type = parsecli.HerokuFormat
		var newHerokuApp bool
		newHerokuApp, appConfig, err = herokucmd.GetLinkedHerokuAppConfig(app, e)
		if err != nil {
			return err
		}
		isNew = isNew || newHerokuApp

	case "parse":
		e.Type = parsecli.ParseFormat
		appConfig = parsecmd.GetParseAppConfig(app)
	}

	dumpTemplate, err := n.setupSample(e, app.Name, appConfig, isNew, nonInteractive)
	if err != nil {
		return err
	}
	if err := n.configureSample(addCmd, app.Name, appConfig, nil, e); err != nil {
		return err
	}
	if token := apps.Login.Credentials.Token; token != "" {
		email, err := apps.Login.AuthToken(e, token)
		if err != nil {
			return err
		}
		if err := parsecli.SetParserEmail(e, email); err != nil {
			return err
		}
	}

	if dumpTemplate {
		fmt.Fprintf(e.Out, n.cloudCodeHelpMessage(e, app))
	}

	return nil
}