コード例 #1
0
func (factory *AppExaminerCommandFactory) appStatus(context *cli.Context) {

	summaryFlag := context.Bool("summary")
	rateFlag := context.Duration("rate")

	if len(context.Args()) < 1 {
		factory.ui.SayIncorrectUsage("App Name required")
		factory.exitHandler.Exit(exit_codes.InvalidSyntax)
		return
	}

	appName := context.Args()[0]

	appInfo, err := factory.appExaminer.AppStatus(appName)
	if err != nil {
		factory.ui.SayLine(err.Error())
		factory.exitHandler.Exit(exit_codes.CommandFailed)
		return
	}

	factory.printAppInfo(appInfo)

	if summaryFlag || rateFlag != 0 {
		factory.printInstanceSummary(appInfo.ActualInstances)
	} else {
		factory.printInstanceInfo(appInfo.ActualInstances)
	}

	if rateFlag == 0 {
		return
	}

	linesWritten := appStatusLinesWritten(appInfo)
	closeChan := make(chan struct{})
	defer factory.ui.Say(cursor.Show())
	factory.ui.Say(cursor.Hide())

	factory.exitHandler.OnExit(func() {
		closeChan <- struct{}{}
		factory.ui.Say(cursor.Show())
	})

	for {
		select {
		case <-closeChan:
			return
		case <-factory.clock.NewTimer(rateFlag).C():
			appInfo, err = factory.appExaminer.AppStatus(appName)
			if err != nil {
				factory.ui.SayLine("Error getting status: " + err.Error())
				return
			}
			factory.ui.Say(cursor.Up(linesWritten))
			factory.printAppInfo(appInfo)
			factory.printInstanceSummary(appInfo.ActualInstances)
			linesWritten = appStatusLinesWritten(appInfo)
		}
	}
}
コード例 #2
0
func (factory *AppExaminerCommandFactory) visualizeCells(context *cli.Context) {
	rate := context.Duration("rate")
	graphicalFlag := context.Bool("graphical")

	if graphicalFlag {
		err := factory.graphicalVisualizer.PrintDistributionChart(rate)
		if err != nil {
			factory.ui.SayLine("Error Visualization: " + err.Error())
			factory.exitHandler.Exit(exit_codes.CommandFailed)
		}
		return
	}

	factory.ui.SayLine(colors.Bold("Distribution"))
	linesWritten := factory.printDistribution()

	if rate == 0 {
		return
	}

	closeChan := make(chan struct{})
	factory.ui.Say(cursor.Hide())

	factory.exitHandler.OnExit(func() {
		closeChan <- struct{}{}
		factory.ui.Say(cursor.Show())

	})

	for {
		select {
		case <-closeChan:
			return
		case <-factory.clock.NewTimer(rate).C():
			factory.ui.Say(cursor.Up(linesWritten))
			linesWritten = factory.printDistribution()
		}
	}
}
コード例 #3
0
				Eventually(outputBuffer).Should(test_helpers.Say(cursor.Up(1)))
				Eventually(outputBuffer).Should(test_helpers.SayLine("Error visualizing: Spilled the Paint" + cursor.ClearToEndOfLine()))
				Eventually(outputBuffer).Should(test_helpers.Say(cursor.ClearToEndOfDisplay()))

				Consistently(closeChan).ShouldNot(BeClosed())
			})

			It("ensures the user's cursor is visible even if they interrupt ltc", func() {
				closeChan = test_helpers.AsyncExecuteCommandWithArgs(visualizeCommand, []string{"--rate=1s"})

				Eventually(outputBuffer).Should(test_helpers.Say(cursor.Hide()))
				fakeExitHandler.Exit(exit_codes.SigInt)
				Eventually(closeChan).Should(BeClosed())

				Expect(outputBuffer).To(test_helpers.Say(cursor.Show()))
				Expect(fakeExitHandler.ExitCalledWith).To(Equal([]int{exit_codes.SigInt}))
			})
		})

		Context("when the graphical flag is passed", func() {
			It("makes a successful call to the graphical visualizer and returns", func() {
				test_helpers.ExecuteCommandWithArgs(visualizeCommand, []string{"--graphical"})

				Consistently(outputBuffer).ShouldNot(test_helpers.Say("Distribution"))

				Expect(fakeGraphicalVisualizer.PrintDistributionChartCallCount()).To(Equal(1))
				Expect(fakeGraphicalVisualizer.PrintDistributionChartArgsForCall(0)).To(BeZero())
			})

			It("prints the error from an unsuccessful call to the graphical visualizer", func() {
コード例 #4
0
func (factory *AppExaminerCommandFactory) appStatus(context *cli.Context) {
	detailedFlag := context.Bool("detailed")
	rateFlag := context.Duration("rate")

	if len(context.Args()) < 1 {
		factory.ui.SayIncorrectUsage("App Name required")
		factory.exitHandler.Exit(exit_codes.InvalidSyntax)
		return
	}

	appName := context.Args()[0]

	writer := new(bytes.Buffer)

	appInfo, err := factory.appExaminer.AppStatus(appName)
	if err != nil {
		factory.ui.SayLine(err.Error())
		factory.exitHandler.Exit(exit_codes.CommandFailed)
		return
	}

	factory.printAppInfo(writer, appInfo)

	if rateFlag != 0 {
		if detailedFlag {
			factory.ui.SayLine("WARNING: flags '--detailed' and '--rate' are incompatible.")
		}
		factory.printInstanceSummary(writer, appInfo.ActualInstances)
	} else if detailedFlag {
		factory.printInstanceInfo(writer, appInfo.ActualInstances)
	} else {
		factory.printInstanceSummary(writer, appInfo.ActualInstances)
	}

	factory.ui.Write(writer.Bytes())

	if rateFlag == 0 {
		return
	}

	linesWritten := factory.lineCount(writer.Bytes())

	closeChan := make(chan struct{})
	defer factory.ui.Say(cursor.Show())
	factory.ui.Say(cursor.Hide())

	factory.exitHandler.OnExit(func() {
		closeChan <- struct{}{}
		factory.ui.Say(cursor.Show())
	})

	for {
		select {
		case <-closeChan:
			return
		case <-factory.clock.NewTimer(rateFlag).C():
			appInfo, err = factory.appExaminer.AppStatus(appName)
			if err != nil {
				factory.ui.SayLine("Error getting status: " + err.Error())
				return
			}
			factory.ui.Say(cursor.Up(linesWritten))
			writer = new(bytes.Buffer)
			factory.printAppInfo(writer, appInfo)
			factory.printInstanceSummary(writer, appInfo.ActualInstances)
			factory.ui.Write(writer.Bytes())
			linesWritten = factory.lineCount(writer.Bytes())
		}
	}
}