Exemplo 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
}
Exemplo n.º 2
0
func AddSelectedParseApp(
	appName string,
	appConfig *parsecli.ParseAppConfig,
	args []string,
	makeDefault, verbose bool,
	e *parsecli.Env,
) error {
	config, err := parsecli.ConfigFromDir(e.Root)
	if err != nil {
		return err
	}
	parseConfig, ok := config.(*parsecli.ParseConfig)
	if !ok {
		return stackerr.New("Invalid Cloud Code config.")
	}

	// add app to config
	if _, ok := parseConfig.Applications[appName]; ok {
		return stackerr.Newf("App %s has already been added", appName)
	}

	parseConfig.Applications[appName] = appConfig

	if len(args) > 0 && args[0] != "" {
		alias := args[0]
		aliasConfig, ok := parseConfig.Applications[alias]
		if !ok {
			parseConfig.Applications[alias] = &parsecli.ParseAppConfig{Link: appName}
		}
		if ok && aliasConfig.GetLink() != "" {
			fmt.Fprintf(e.Out, "Overwriting alias: %q to point to %q\n", alias, appName)
			parseConfig.Applications[alias] = &parsecli.ParseAppConfig{Link: appName}
		}
	}

	if makeDefault {
		if _, ok := parseConfig.Applications[parsecli.DefaultKey]; ok {
			return stackerr.New(`Default key already set. To override default, use command "parse default"`)
		}
		parseConfig.Applications[parsecli.DefaultKey] = &parsecli.ParseAppConfig{Link: appName}
	}

	if err := parsecli.StoreConfig(e, parseConfig); err != nil {
		return err
	}
	if verbose {
		fmt.Fprintf(e.Out, "Written config for %q\n", appName)
		if makeDefault {
			fmt.Fprintf(e.Out, "Set %q as default\n", appName)
		}
	}

	return nil
}
Exemplo n.º 3
0
func newDefaultParseConfig(t testing.TB, h *parsecli.Harness) *parsecli.ParseConfig {
	c, err := parsecli.ConfigFromDir(h.Env.Root)
	ensure.Nil(t, err)

	config, ok := c.(*parsecli.ParseConfig)
	ensure.True(t, ok)
	config.Applications = map[string]*parsecli.ParseAppConfig{
		"first":             {},
		"second":            {},
		parsecli.DefaultKey: {Link: "first"},
	}
	config.ProjectConfig = &parsecli.ProjectConfig{
		Type:  parsecli.LegacyParseFormat,
		Parse: &parsecli.ParseProjectConfig{},
	}
	ensure.Nil(t, parsecli.StoreConfig(h.Env, config))

	return config
}