Esempio n. 1
0
func (d *defaultCmd) run(e *parsecli.Env, args []string) error {
	var newDefault string
	if len(args) > 1 {
		return stackerr.Newf("unexpected arguments, only an optional app name is expected: %v", args)
	}
	if len(args) == 1 {
		newDefault = args[0]
	}

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

	if config.GetNumApps() == 0 {
		return stackerr.New("No apps are associated with this project. You can add some with parse add")
	}

	defaultApp := config.GetDefaultApp()

	switch newDefault {
	case "":
		return parsecli.PrintDefault(e, defaultApp)
	default:
		return parsecli.SetDefault(e, newDefault, defaultApp, config)
	}
}
Esempio n. 2
0
func TestPrintDefaultSet(t *testing.T) {
	t.Parallel()
	h, _, _ := newDefaultCmdHarness(t)
	defer h.Stop()
	parsecli.PrintDefault(h.Env, "first")
	ensure.DeepEqual(t, h.Out.String(),
		`Current default app is first
`)
}
Esempio n. 3
0
func TestPrintDefaultNotSet(t *testing.T) {
	t.Parallel()
	h, _, _ := newDefaultCmdHarness(t)
	defer h.Stop()
	ensure.Err(t, parsecli.PrintDefault(h.Env, ""), regexp.MustCompile("No app is set as default app"))
}