Example #1
0
File: stop.go Project: KaiYoung/cli
func (s *Stop) Run(c *cli.Context) {
	app := s.appReq.GetApplication()

	if app.State == "stopped" {
		s.ui.Say(term.Magenta("Application " + app.Name + " is already stopped."))
		return
	}

	s.ui.Say("Stopping %s...", term.Cyan(app.Name))

	err := s.appRepo.Stop(app)
	if err != nil {
		s.ui.Failed("Error stopping application.", err)
		return
	}
	s.ui.Ok()
}
Example #2
0
func (s *Start) ApplicationStart(app cf.Application) {
	if app.State == "started" {
		s.ui.Say(term.Magenta("Application " + app.Name + " is already started."))
		return
	}

	s.ui.Say("Starting %s...", term.Cyan(app.Name))

	err := s.appRepo.Start(app)
	if err != nil {
		s.ui.Failed("Error starting application.", err)
		return
	}

	s.ui.Ok()

	instances, errorCode, err := s.appRepo.GetInstances(app)

	for err != nil {
		if errorCode != 170002 {
			s.ui.Say("")
			s.ui.Failed("Error staging application", err)
			return
		}

		s.ui.Wait(1 * time.Second)
		instances, errorCode, err = s.appRepo.GetInstances(app)
		s.ui.LoadingIndication()
	}

	s.ui.Say("")

	s.startTime = time.Now()

	for s.displayInstancesStatus(app, instances) {
		s.ui.Wait(1 * time.Second)
		instances, _, _ = s.appRepo.GetInstances(app)
	}
}
Example #3
0
func (t Target) setNewTarget(target string) {
	t.ui.Say("Setting target to %s...", term.Yellow(target))

	request, err := api.NewRequest("GET", target+"/v2/info", "", nil)

	if err != nil {
		t.ui.Failed("URL invalid.", err)
		return
	}

	scheme := request.URL.Scheme
	if scheme != "http" && scheme != "https" {
		t.ui.Failed("API Endpoints should start with https:// or http://", nil)
		return
	}

	serverResponse := new(InfoResponse)
	_, err = api.PerformRequestAndParseResponse(request, &serverResponse)

	if err != nil {
		t.ui.Failed("", err)
		return
	}

	err = t.saveTarget(target, serverResponse)

	if err != nil {
		t.ui.Failed("Error saving configuration", err)
		return
	}

	t.ui.Ok()

	if scheme == "http" {
		t.ui.Say(term.Magenta("\nWarning: Insecure http API Endpoint detected. Secure https API Endpoints are recommended.\n"))
	}
	t.ui.ShowConfiguration(t.config)
}