예제 #1
0
func TestSetDefaultWithApp(t *testing.T) {
	t.Parallel()
	h, _, config := newDefaultCmdHarness(t)
	defer h.Stop()
	ensure.Nil(t, parsecli.SetDefault(h.Env, "first", "first", config))
	ensure.DeepEqual(t, h.Out.String(), "Default app set to first.\n")
}
예제 #2
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)
	}
}
예제 #3
0
func TestSetDefaultInvalid(t *testing.T) {
	t.Parallel()
	h, _, config := newDefaultCmdHarness(t)
	defer h.Stop()
	ensure.Err(
		t,
		parsecli.SetDefault(h.Env, "invalid", "", config),
		regexp.MustCompile(`Invalid application name "invalid". Please select from the valid applications printed above.`),
	)
	ensure.DeepEqual(t, h.Out.String(),
		`The following apps are associated with Cloud Code in the current directory:
* first
  second
`)
}