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) } }
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 `) }
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")) }