本文整理匯總了Golang中github.com/cloudfoundry-incubator/lattice/ltc/terminal/colors.Green函數的典型用法代碼示例。如果您正苦於以下問題:Golang Green函數的具體用法?Golang Green怎麽用?Golang Green使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Green函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: WaitForAppCreation
func (factory *AppRunnerCommandFactory) WaitForAppCreation(appName string, pollTimeout time.Duration, instanceCount int, noRoutesFlag bool, routeOverrides app_runner.RouteOverrides, tcpRoutes app_runner.TcpRoutes) {
factory.UI.SayLine("Creating App: " + appName)
go factory.TailedLogsOutputter.OutputTailedLogs(appName)
defer factory.TailedLogsOutputter.StopOutputting()
ok := factory.pollUntilAllInstancesRunning(pollTimeout, appName, instanceCount, "start")
if noRoutesFlag {
factory.UI.SayLine(colors.Green(appName + " is now running."))
return
} else if ok {
factory.UI.SayLine(colors.Green(appName + " is now running."))
factory.UI.SayLine("App is reachable at:")
} else {
factory.UI.SayLine("App will be reachable at:")
}
if tcpRoutes != nil {
for _, tcpRoute := range tcpRoutes {
factory.UI.SayLine(colors.Green(factory.externalPortMappingForApp(tcpRoute.ExternalPort, tcpRoute.Port)))
}
}
if routeOverrides != nil {
for _, route := range routeOverrides {
factory.UI.SayLine(colors.Green(factory.urlForAppName(route.HostnamePrefix)))
}
} else {
factory.UI.SayLine(colors.Green(factory.urlForAppName(appName)))
}
}
示例2: displayDefaultRoutes
func (factory *AppRunnerCommandFactory) displayDefaultRoutes(appName string, monitorPort uint16, exposedPorts []uint16) {
factory.UI.SayLine(colors.Green(factory.urlForAppName(appName)))
primaryPort := route_helpers.GetPrimaryPort(monitorPort, exposedPorts)
appRoutes := route_helpers.BuildDefaultRoutingInfo(appName, exposedPorts, primaryPort, factory.Domain)
for _, appRoute := range appRoutes {
factory.UI.SayLine(colors.Green(factory.urlForAppNameAndPort(appName, appRoute.Port)))
}
}
示例3: submitLrp
func (factory *AppRunnerCommandFactory) submitLrp(context *cli.Context) {
filePath := context.Args().First()
if filePath == "" {
factory.UI.SayLine("Path to JSON is required")
factory.ExitHandler.Exit(exit_codes.InvalidSyntax)
return
}
jsonBytes, err := ioutil.ReadFile(filePath)
if err != nil {
factory.UI.SayLine(fmt.Sprintf("Error reading file: %s", err.Error()))
factory.ExitHandler.Exit(exit_codes.FileSystemError)
return
}
lrpName, err := factory.AppRunner.SubmitLrp(jsonBytes)
if err != nil {
factory.UI.SayLine(fmt.Sprintf("Error creating %s: %s", lrpName, err.Error()))
factory.ExitHandler.Exit(exit_codes.CommandFailed)
return
}
factory.UI.SayLine(colors.Green(fmt.Sprintf("Successfully submitted %s.", lrpName)))
factory.UI.SayLine(fmt.Sprintf("To view the status of your application: ltc status %s", lrpName))
}
示例4: printDistribution
func (factory *AppExaminerCommandFactory) printDistribution() int {
defer factory.ui.Say(cursor.ClearToEndOfDisplay())
cells, err := factory.appExaminer.ListCells()
if err != nil {
factory.ui.Say("Error visualizing: " + err.Error())
factory.ui.Say(cursor.ClearToEndOfLine())
factory.ui.SayNewLine()
return 1
}
for _, cell := range cells {
factory.ui.Say(cell.CellID)
if cell.Missing {
factory.ui.Say(colors.Red("[MISSING]"))
}
factory.ui.Say(": ")
if cell.RunningInstances == 0 && cell.ClaimedInstances == 0 && !cell.Missing {
factory.ui.Say(colors.Red("empty"))
} else {
factory.ui.Say(colors.Green(strings.Repeat("•", cell.RunningInstances)))
factory.ui.Say(colors.Yellow(strings.Repeat("•", cell.ClaimedInstances)))
}
factory.ui.Say(cursor.ClearToEndOfLine())
factory.ui.SayNewLine()
}
return len(cells)
}
示例5: colorInstances
func colorInstances(appInfo app_examiner.AppInfo) string {
instances := fmt.Sprintf("%d/%d", appInfo.ActualRunningInstances, appInfo.DesiredInstances)
if appInfo.ActualRunningInstances == appInfo.DesiredInstances {
return colors.Green(instances)
} else if appInfo.ActualRunningInstances == 0 {
return colors.Red(instances)
}
return colors.Yellow(instances)
}
示例6: setAppInstances
func (factory *AppRunnerCommandFactory) setAppInstances(pollTimeout time.Duration, appName string, instances int) {
if err := factory.AppRunner.ScaleApp(appName, instances); err != nil {
factory.UI.SayLine(fmt.Sprintf("Error Scaling App to %d instances: %s", instances, err))
factory.ExitHandler.Exit(exit_codes.CommandFailed)
return
}
factory.UI.SayLine(fmt.Sprintf("Scaling %s to %d instances", appName, instances))
if ok := factory.pollUntilAllInstancesRunning(pollTimeout, appName, instances, "scale"); ok {
factory.UI.SayLine(colors.Green("App Scaled Successfully"))
}
}
示例7: deleteTask
func (factory *TaskRunnerCommandFactory) deleteTask(context *cli.Context) {
taskGuid := context.Args().First()
if taskGuid == "" {
factory.ui.SayIncorrectUsage("Please input a valid TASK_GUID")
factory.exitHandler.Exit(exit_codes.InvalidSyntax)
return
}
if err := factory.taskRunner.DeleteTask(taskGuid); err != nil {
factory.ui.SayLine(fmt.Sprintf(colors.Red("Error deleting %s: %s"), taskGuid, err.Error()))
factory.exitHandler.Exit(exit_codes.CommandFailed)
return
}
factory.ui.SayLine(colors.Green("OK"))
}
示例8: submitTask
func (factory *TaskRunnerCommandFactory) submitTask(context *cli.Context) {
filePath := context.Args().First()
if filePath == "" {
factory.ui.SayLine("Path to JSON is required")
factory.exitHandler.Exit(exit_codes.InvalidSyntax)
return
}
jsonBytes, err := ioutil.ReadFile(filePath)
if err != nil {
factory.ui.SayLine("Error reading file: " + err.Error())
factory.exitHandler.Exit(exit_codes.FileSystemError)
return
}
taskName, err := factory.taskRunner.SubmitTask(jsonBytes)
if err != nil {
factory.ui.SayLine(fmt.Sprintf("Error submitting %s: %s", taskName, err))
factory.exitHandler.Exit(exit_codes.CommandFailed)
return
}
factory.ui.SayLine(colors.Green("Successfully submitted " + taskName))
}
示例9: task
func (factory *TaskExaminerCommandFactory) task(context *cli.Context) {
taskName := context.Args().First()
if taskName == "" {
factory.ui.SayIncorrectUsage("")
factory.exitHandler.Exit(exit_codes.InvalidSyntax)
return
}
taskInfo, err := factory.taskExaminer.TaskStatus(taskName)
if err != nil {
if err.Error() == task_examiner.TaskNotFoundErrorMessage {
factory.ui.Say(colors.Red(fmt.Sprintf("No task '%s' was found", taskName)))
factory.exitHandler.Exit(exit_codes.CommandFailed)
return
}
factory.ui.Say(colors.Red("Error fetching task result: " + err.Error()))
factory.exitHandler.Exit(exit_codes.CommandFailed)
return
}
w := tabwriter.NewWriter(factory.ui, 9, 8, 1, '\t', 0)
fmt.Fprintf(w, "%s\t%s\n", "Task Name", taskInfo.TaskGuid)
fmt.Fprintf(w, "%s\t%s\n", "Cell ID", taskInfo.CellID)
if taskInfo.State == "PENDING" || taskInfo.State == "CLAIMED" || taskInfo.State == "RUNNING" {
fmt.Fprintf(w, "%s\t%s\n", "Status", colors.Yellow(taskInfo.State))
} else if (taskInfo.State == "COMPLETED" || taskInfo.State == "RESOLVING") && !taskInfo.Failed {
fmt.Fprintf(w, "%s\t%s\n", "Status", colors.Green(taskInfo.State))
fmt.Fprintf(w, "%s\t%s\n", "Result", taskInfo.Result)
} else if taskInfo.Failed {
fmt.Fprintf(w, "%s\t%s\n", "Status", colors.Red(taskInfo.State))
fmt.Fprintf(w, "%s\t%s\n", "Failure Reason", taskInfo.FailureReason)
}
w.Flush()
}
示例10:
})
It("launches the specified droplet with tcp routes", func() {
fakeAppExaminer.RunningAppInstancesInfoReturns(1, false, nil)
args := []string{
"--http-routes=ninetyninety:4444,fourtyfourfourtyfour:9090",
"--tcp-routes=50000:5222,50001:5223",
"droppy",
"droplet-name",
"--",
"start-em",
}
test_helpers.ExecuteCommandWithArgs(launchDropletCommand, args)
Expect(outputBuffer).To(test_helpers.SayLine("Creating App: droppy"))
Expect(outputBuffer).To(test_helpers.SayLine(colors.Green("droppy is now running.")))
Expect(outputBuffer).To(test_helpers.SayLine("App is reachable at:"))
Expect(outputBuffer).To(test_helpers.SayLine(colors.Green("http://ninetyninety.192.168.11.11.xip.io")))
Expect(outputBuffer).To(test_helpers.SayLine(colors.Green("http://fourtyfourfourtyfour.192.168.11.11.xip.io")))
Expect(fakeDropletRunner.LaunchDropletCallCount()).To(Equal(1))
appName, dropletNameParam, startCommandParam, _, appEnvParam := fakeDropletRunner.LaunchDropletArgsForCall(0)
Expect(appName).To(Equal("droppy"))
Expect(dropletNameParam).To(Equal("droplet-name"))
Expect(startCommandParam).To(Equal("start-em"))
Expect(appEnvParam.Instances).To(Equal(1))
Expect(appEnvParam.NoRoutes).To(BeFalse())
Expect(appEnvParam.RouteOverrides).To(ContainExactly(app_runner.RouteOverrides{
{HostnamePrefix: "ninetyninety", Port: 4444},
{HostnamePrefix: "fourtyfourfourtyfour", Port: 9090},
}))
示例11:
Context("when the json file exists", func() {
BeforeEach(func() {
tmpDir = os.TempDir()
tmpFile, err = ioutil.TempFile(tmpDir, "tmp_json")
Expect(err).ToNot(HaveOccurred())
Expect(ioutil.WriteFile(tmpFile.Name(), []byte(`{"Value":"test value"}`), 0700)).To(Succeed())
})
It("creates an app from json", func() {
fakeAppRunner.SubmitLrpReturns("my-json-app", nil)
args := []string{tmpFile.Name()}
test_helpers.ExecuteCommandWithArgs(submitLrpCommand, args)
Expect(outputBuffer).To(test_helpers.Say(colors.Green("Successfully submitted my-json-app.")))
Expect(outputBuffer).To(test_helpers.Say("To view the status of your application: ltc status my-json-app"))
Expect(fakeAppRunner.SubmitLrpCallCount()).To(Equal(1))
Expect(fakeAppRunner.SubmitLrpArgsForCall(0)).To(Equal([]byte(`{"Value":"test value"}`)))
})
It("prints an error returned by the app_runner", func() {
fakeAppRunner.SubmitLrpReturns("app-that-broke", errors.New("some error"))
args := []string{tmpFile.Name()}
test_helpers.ExecuteCommandWithArgs(submitLrpCommand, args)
Expect(outputBuffer).To(test_helpers.Say("Error creating app-that-broke: some error"))
Expect(fakeAppRunner.SubmitLrpCallCount()).To(Equal(1))
Expect(fakeExitHandler.ExitCalledWith).To(Equal([]int{exit_codes.CommandFailed}))
})
示例12:
app_runner.RouteOverride{HostnamePrefix: "route-3000-yay", Port: 3000},
app_runner.RouteOverride{HostnamePrefix: "route-1111-wahoo", Port: 1111},
app_runner.RouteOverride{HostnamePrefix: "route-1111-me-too", Port: 1111},
}))
Expect(createAppParams.NoRoutes).To(BeFalse())
Expect(createAppParams.WorkingDir).To(Equal("/applications"))
Expect(createAppParams.Setup).To(BeAssignableToTypeOf(&models.DownloadAction{}))
reqSetup, ok := createAppParams.Setup.(*models.DownloadAction)
Expect(ok).To(BeTrue())
Expect(reqSetup.From).To(Equal("http://file_server.service.dc1.consul:8080/v1/static/healthcheck.tgz"))
Expect(reqSetup.To).To(Equal("/tmp"))
Expect(reqSetup.User).To(Equal("vcap"))
Expect(outputBuffer).To(test_helpers.Say("Creating App: cool-web-app\n"))
Expect(outputBuffer).To(test_helpers.Say(colors.Green("cool-web-app is now running.\n")))
Expect(outputBuffer).To(test_helpers.Say("App is reachable at:\n"))
Expect(outputBuffer).To(test_helpers.Say(colors.Green("http://route-3000-yay.192.168.11.11.xip.io\n")))
Expect(outputBuffer).To(test_helpers.Say(colors.Green("http://route-1111-wahoo.192.168.11.11.xip.io\n")))
Expect(outputBuffer).To(test_helpers.Say(colors.Green("http://route-1111-me-too.192.168.11.11.xip.io\n")))
})
Context("when the PROCESS_GUID is passed in as --env", func() {
It("sets the PROCESS_GUID to the value passed in", func() {
fakeDockerMetadataFetcher.FetchMetadataReturns(&docker_metadata_fetcher.ImageMetadata{StartCommand: []string{""}}, nil)
fakeAppExaminer.RunningAppInstancesInfoReturns(1, false, nil)
args := []string{
"app-to-start",
"fun-org/app",
"--env=PROCESS_GUID=MyHappyGuid",
}
示例13:
Expect(colorizer("\t")).To(Equal("\t"))
Expect(colorizer("\r")).To(Equal("\r"))
})
}
Describe("Red", func() {
It("adds the red color code", func() {
Expect(colors.Red("ERROR NOT GOOD")).To(Equal("\x1b[91mERROR NOT GOOD\x1b[0m"))
})
itShouldNotColorizeWhitespace(colors.Red)
})
Describe("Green", func() {
It("adds the green color code", func() {
Expect(colors.Green("TOO GOOD")).To(Equal("\x1b[32mTOO GOOD\x1b[0m"))
})
itShouldNotColorizeWhitespace(colors.Green)
})
Describe("Cyan", func() {
It("adds the cyan color code", func() {
Expect(colors.Cyan("INFO")).To(Equal("\x1b[36mINFO\x1b[0m"))
})
itShouldNotColorizeWhitespace(colors.Cyan)
})
Describe("Yellow", func() {
It("adds the yellow color code", func() {
示例14:
State: "COMPLETED",
CellID: "cell-01",
Failed: false,
FailureReason: "",
Result: "some-result",
}
fakeTaskExaminer.TaskStatusReturns(taskInfo, nil)
test_helpers.ExecuteCommandWithArgs(taskCommand, []string{"boop"})
Expect(outputBuffer).To(test_helpers.Say("Task Name"))
Expect(outputBuffer).To(test_helpers.Say("boop"))
Expect(outputBuffer).To(test_helpers.Say("Cell ID"))
Expect(outputBuffer).To(test_helpers.Say("cell-01"))
Expect(outputBuffer).To(test_helpers.Say("Status"))
Expect(outputBuffer).To(test_helpers.Say(colors.Green("COMPLETED")))
Expect(outputBuffer).To(test_helpers.Say("Result"))
Expect(outputBuffer).To(test_helpers.Say("some-result"))
Expect(outputBuffer).NotTo(test_helpers.Say("Failure Reason"))
Expect(fakeTaskExaminer.TaskStatusCallCount()).To(Equal(1))
Expect(fakeTaskExaminer.TaskStatusArgsForCall(0)).To(Equal("boop"))
})
It("displays failure reason for a failed task result", func() {
taskInfo := task_examiner.TaskInfo{
TaskGuid: "boop",
State: "COMPLETED",
CellID: "cell-01",
Failed: true,
FailureReason: "womp womp",
示例15:
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/cloudfoundry-incubator/lattice/ltc/app_examiner"
"github.com/cloudfoundry-incubator/lattice/ltc/app_examiner/command_factory/presentation"
"github.com/cloudfoundry-incubator/lattice/ltc/terminal/colors"
"github.com/cloudfoundry-incubator/receptor"
)
var _ = Describe("Presentation", func() {
Describe("ColorInstanceState", func() {
It("colors RUNNING green", func() {
instanceInfo := app_examiner.InstanceInfo{State: string(receptor.ActualLRPStateRunning)}
Expect(presentation.ColorInstanceState(instanceInfo)).To(Equal(colors.Green(string(receptor.ActualLRPStateRunning))))
})
It("colors CLAIMED yellow", func() {
instanceInfo := app_examiner.InstanceInfo{State: string(receptor.ActualLRPStateClaimed)}
Expect(presentation.ColorInstanceState(instanceInfo)).To(Equal(colors.Yellow(string(receptor.ActualLRPStateClaimed))))
})
Context("when there is a placement error", func() {
It("colors UNCLAIMED red", func() {
instanceInfo := app_examiner.InstanceInfo{
State: string(receptor.ActualLRPStateUnclaimed),
PlacementError: "I misplaced my cells. Uh oh.",
}
Expect(presentation.ColorInstanceState(instanceInfo)).To(Equal(colors.Red(string(receptor.ActualLRPStateUnclaimed))))