當前位置: 首頁>>代碼示例>>Golang>>正文


Golang terminal.HeaderColor函數代碼示例

本文整理匯總了Golang中cf/terminal.HeaderColor函數的典型用法代碼示例。如果您正苦於以下問題:Golang HeaderColor函數的具體用法?Golang HeaderColor怎麽用?Golang HeaderColor使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了HeaderColor函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Run

func (cmd *App) Run(c *cli.Context) {
	app := cmd.appReq.GetApplication()
	cmd.ui.Say("Showing health and status for app %s...", term.EntityNameColor(app.Name))

	summary, err := cmd.appSummaryRepo.GetSummary(app)
	if err != nil {
		cmd.ui.Failed(err.Error())
		return
	}

	cmd.ui.Ok()
	cmd.ui.Say("\n%s %s", term.HeaderColor("health:"), coloredState(summary.App.Health()))
	cmd.ui.Say("%s %s x %d instances", term.HeaderColor("usage:"), byteSize(summary.App.Memory*MEGABYTE), summary.App.Instances)
	cmd.ui.Say("%s %s\n", term.HeaderColor("urls:"), strings.Join(summary.App.Urls, ", "))

	table := [][]string{
		[]string{"", "status", "since", "cpu", "memory", "disk"},
	}

	for index, instance := range summary.Instances {
		table = append(table, []string{
			fmt.Sprintf("#%d", index),
			string(instance.State),
			instance.Since.Format("2006-01-02 03:04:05 PM"),
			fmt.Sprintf("%.1f%%", instance.CpuUsage),
			fmt.Sprintf("%s of %s", byteSize(instance.MemUsage), byteSize(instance.MemQuota)),
			fmt.Sprintf("%s of %s", byteSize(instance.DiskUsage), byteSize(instance.DiskQuota)),
		})
	}

	cmd.ui.DisplayTable(table, cmd.coloringFunc)
}
開發者ID:jbayer,項目名稱:cli,代碼行數:32,代碼來源:app.go

示例2: ShowApp

func (cmd *ShowApp) ShowApp(app cf.Application) {

	cmd.ui.Say("Showing health and status for app %s in org %s / space %s as %s...",
		terminal.EntityNameColor(app.Name),
		terminal.EntityNameColor(cmd.config.OrganizationFields.Name),
		terminal.EntityNameColor(cmd.config.SpaceFields.Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	appSummary, apiResponse := cmd.appSummaryRepo.GetSummary(app.Guid)
	appIsStopped := apiResponse.ErrorCode == cf.APP_STOPPED ||
		apiResponse.ErrorCode == cf.APP_NOT_STAGED ||
		appSummary.State == "stopped"

	if apiResponse.IsNotSuccessful() && !appIsStopped {
		cmd.ui.Failed(apiResponse.Message)
		return
	}

	var instances []cf.AppInstanceFields
	instances, apiResponse = cmd.appInstancesRepo.GetInstances(app.Guid)
	if apiResponse.IsNotSuccessful() && !appIsStopped {
		cmd.ui.Failed(apiResponse.Message)
		return
	}

	cmd.ui.Ok()
	cmd.ui.Say("\n%s %s", terminal.HeaderColor("requested state:"), coloredAppState(appSummary.ApplicationFields))
	cmd.ui.Say("%s %s", terminal.HeaderColor("instances:"), coloredAppInstances(appSummary.ApplicationFields))
	cmd.ui.Say("%s %s x %d instances", terminal.HeaderColor("usage:"), formatters.ByteSize(appSummary.Memory*formatters.MEGABYTE), appSummary.InstanceCount)

	var urls []string
	for _, route := range appSummary.RouteSummaries {
		urls = append(urls, route.URL())
	}

	cmd.ui.Say("%s %s\n", terminal.HeaderColor("urls:"), strings.Join(urls, ", "))

	if appIsStopped {
		cmd.ui.Say("There are no running instances of this app.")
		return
	}

	table := [][]string{
		[]string{"", "state", "since", "cpu", "memory", "disk"},
	}

	for index, instance := range instances {
		table = append(table, []string{
			fmt.Sprintf("#%d", index),
			coloredInstanceState(instance),
			instance.Since.Format("2006-01-02 03:04:05 PM"),
			fmt.Sprintf("%.1f%%", instance.CpuUsage*100),
			fmt.Sprintf("%s of %s", formatters.ByteSize(instance.MemUsage), formatters.ByteSize(instance.MemQuota)),
			fmt.Sprintf("%s of %s", formatters.ByteSize(instance.DiskUsage), formatters.ByteSize(instance.DiskQuota)),
		})
	}

	cmd.ui.DisplayTable(table)
}
開發者ID:nsnt,項目名稱:cli,代碼行數:60,代碼來源:show_app.go

示例3: Run

func (cmd *ShowApp) Run(c *cli.Context) {
	app := cmd.appReq.GetApplication()
	cmd.ui.Say("Showing health and status for app %s in org %s / space %s as %s...",
		terminal.EntityNameColor(app.Name),
		terminal.EntityNameColor(cmd.config.Organization.Name),
		terminal.EntityNameColor(cmd.config.Space.Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	summary, apiResponse := cmd.appSummaryRepo.GetSummary(app)
	appIsStopped := apiResponse.ErrorCode == cf.APP_STOPPED || apiResponse.ErrorCode == cf.APP_NOT_STAGED

	if apiResponse.IsNotSuccessful() && !appIsStopped {
		cmd.ui.Failed(apiResponse.Message)
		return
	}

	cmd.ui.Ok()
	cmd.ui.Say("\n%s %s", terminal.HeaderColor("state:"), coloredAppState(summary.App))
	cmd.ui.Say("%s %s", terminal.HeaderColor("instances:"), coloredAppInstaces(summary.App))
	cmd.ui.Say("%s %s x %d instances", terminal.HeaderColor("usage:"), formatters.ByteSize(summary.App.Memory*formatters.MEGABYTE), summary.App.Instances)

	var urls []string
	for _, route := range summary.App.Routes {
		urls = append(urls, route.URL())
	}
	cmd.ui.Say("%s %s\n", terminal.HeaderColor("urls:"), strings.Join(urls, ", "))

	if appIsStopped {
		return
	}

	table := [][]string{
		[]string{"", "status", "since", "cpu", "memory", "disk"},
	}

	for index, instance := range summary.Instances {
		table = append(table, []string{
			fmt.Sprintf("#%d", index),
			coloredInstanceState(instance),
			instance.Since.Format("2006-01-02 03:04:05 PM"),
			fmt.Sprintf("%.1f%%", instance.CpuUsage),
			fmt.Sprintf("%s of %s", formatters.ByteSize(instance.MemUsage), formatters.ByteSize(instance.MemQuota)),
			fmt.Sprintf("%s of %s", formatters.ByteSize(instance.DiskUsage), formatters.ByteSize(instance.DiskQuota)),
		})
	}

	cmd.ui.DisplayTable(table)
}
開發者ID:jalateras,項目名稱:cli,代碼行數:49,代碼來源:show_app.go

示例4: connectToWebsocket

func (repo LoggregatorLogsRepository) connectToWebsocket(location string, app cf.Application, onConnect func(), outputChan chan *logmessage.Message, stopLoggingChan chan bool, printTimeBuffer time.Duration) (err error) {

	trace.Logger.Printf("\n%s %s\n", terminal.HeaderColor("CONNECTING TO WEBSOCKET:"), location)

	config, err := websocket.NewConfig(location, "http://localhost")
	if err != nil {
		return
	}

	config.Header.Add("Authorization", repo.config.AccessToken)
	config.TlsConfig = &tls.Config{InsecureSkipVerify: true}

	ws, err := websocket.DialConfig(config)
	if err != nil {
		return
	}

	onConnect()

	inputChan := make(chan *logmessage.Message, 1000)

	go repo.sendKeepAlive(ws)
	go repo.listenForMessages(ws, inputChan, stopLoggingChan)
	go makeAndStartMessageSorter(inputChan, outputChan, stopLoggingChan, printTimeBuffer)

	return
}
開發者ID:jalateras,項目名稱:cli,代碼行數:27,代碼來源:logs.go

示例5: Run

func (cmd *SpaceUsers) Run(c *cli.Context) {
	spaceName := c.Args()[1]
	org := cmd.orgReq.GetOrganization()

	space, apiResponse := cmd.spaceRepo.FindByNameInOrg(spaceName, org)
	if apiResponse.IsNotSuccessful() {
		cmd.ui.Failed(apiResponse.Message)
	}

	cmd.ui.Say("Getting users in org %s / space %s as %s",
		terminal.EntityNameColor(org.Name),
		terminal.EntityNameColor(space.Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	cmd.userRepo.FindAllInSpaceByRole(space)
	usersByRole, apiResponse := cmd.userRepo.FindAllInSpaceByRole(space)
	if apiResponse.IsNotSuccessful() {
		cmd.ui.Failed(apiResponse.Message)
	}

	cmd.ui.Ok()

	for role, users := range usersByRole {
		cmd.ui.Say("")
		cmd.ui.Say("%s", terminal.HeaderColor(role))

		for _, user := range users {
			cmd.ui.Say("  %s", user.Username)
		}
	}
}
開發者ID:jalateras,項目名稱:cli,代碼行數:32,代碼來源:space_users.go

示例6: Run

func (cmd *OrgUsers) Run(c *cli.Context) {
	org := cmd.orgReq.GetOrganization()
	all := c.Bool("a")

	cmd.ui.Say("Getting users in org %s as %s...",
		terminal.EntityNameColor(org.Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	roles := orgRoles
	if all {
		roles = []string{models.ORG_USER}
	}

	for _, role := range roles {
		displayName := orgRoleToDisplayName[role]

		users, apiErr := cmd.userRepo.ListUsersInOrgForRole(org.Guid, role)

		cmd.ui.Say("")
		cmd.ui.Say("%s", terminal.HeaderColor(displayName))

		for _, user := range users {
			cmd.ui.Say("  %s", user.Username)
		}

		if apiErr != nil {
			cmd.ui.Failed("Failed fetching org-users for role %s.\n%s", apiErr.Error(), displayName)
			return
		}
	}
}
開發者ID:nota-ja,項目名稱:cli,代碼行數:32,代碼來源:org_users.go

示例7: Run

func (cmd *OrgUsers) Run(c *cli.Context) {
	org := cmd.orgReq.GetOrganization()

	cmd.ui.Say("Getting users in org %s as %s...",
		terminal.EntityNameColor(org.Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	usersByRole, apiResponse := cmd.userRepo.FindAllInOrgByRole(org)
	if apiResponse.IsNotSuccessful() {
		cmd.ui.Failed(apiResponse.Message)
		return
	}

	cmd.ui.Ok()

	for role, users := range usersByRole {
		cmd.ui.Say("")
		cmd.ui.Say("%s", terminal.HeaderColor(role))

		for _, user := range users {
			cmd.ui.Say("  %s", user.Username)
		}
	}
}
開發者ID:jalateras,項目名稱:cli,代碼行數:25,代碼來源:org_users.go

示例8: connectToWebsocket

func (repo LoggregatorLogsRepository) connectToWebsocket(location string, onConnect func(), outputChan chan *logmessage.Message, stopLoggingChan chan bool, printTimeBuffer time.Duration) (err error) {
	trace.Logger.Printf("\n%s %s\n", terminal.HeaderColor("CONNECTING TO WEBSOCKET:"), location)

	config, err := websocket.NewConfig(location, "http://localhost")
	if err != nil {
		return
	}

	config.Header.Add("Authorization", repo.config.AccessToken)
	config.TlsConfig = &tls.Config{InsecureSkipVerify: true}

	ws, err := websocket.DialConfig(config)
	if err != nil {
		return
	}
	defer ws.Close()

	onConnect()

	go repo.sendKeepAlive(ws)

	inputChan := make(chan *logmessage.Message, LogBufferSize)
	stopInputChan := make(chan bool, 1)
	go func() {
		defer close(stopInputChan)
		defer close(inputChan)
		repo.listenForMessages(ws, inputChan, stopInputChan)
	}()

	messageQueue := &SortedMessageQueue{printTimeBuffer: printTimeBuffer}

	repo.processMessages(messageQueue, inputChan, outputChan, stopLoggingChan, stopInputChan)

	return
}
開發者ID:pmuellr,項目名稱:cli,代碼行數:35,代碼來源:logs.go

示例9: Run

func (cmd *SpaceUsers) Run(c *cli.Context) {
	spaceName := c.Args()[1]
	org := cmd.orgReq.GetOrganization()

	space, apiErr := cmd.spaceRepo.FindByNameInOrg(spaceName, org.Guid)
	if apiErr != nil {
		cmd.ui.Failed(apiErr.Error())
	}

	cmd.ui.Say("Getting users in org %s / space %s as %s",
		terminal.EntityNameColor(org.Name),
		terminal.EntityNameColor(space.Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	for _, role := range spaceRoles {
		displayName := spaceRoleToDisplayName[role]

		users, apiErr := cmd.userRepo.ListUsersInSpaceForRole(space.Guid, role)

		cmd.ui.Say("")
		cmd.ui.Say("%s", terminal.HeaderColor(displayName))

		for _, user := range users {
			cmd.ui.Say("  %s", user.Username)
		}

		if apiErr != nil {
			cmd.ui.Failed("Failed fetching space-users for role %s.\n%s", apiErr.Error(), displayName)
			return
		}
	}
}
開發者ID:knolleary,項目名稱:cli,代碼行數:33,代碼來源:space_users.go

示例10: Run

func (cmd *OrgUsers) Run(c *cli.Context) {
	org := cmd.orgReq.GetOrganization()

	cmd.ui.Say("Getting users in org %s as %s...",
		terminal.EntityNameColor(org.Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	for _, role := range orgRoles {
		stopChan := make(chan bool)
		defer close(stopChan)

		displayName := orgRoleToDisplayName[role]

		usersChan, statusChan := cmd.userRepo.ListUsersInOrgForRole(org.Guid, role, stopChan)

		cmd.ui.Say("")
		cmd.ui.Say("%s", terminal.HeaderColor(displayName))

		for users := range usersChan {
			for _, user := range users {
				cmd.ui.Say("  %s", user.Username)
			}
		}

		apiStatus := <-statusChan
		if apiStatus.IsNotSuccessful() {
			cmd.ui.Failed("Failed fetching org-users for role %s.\n%s", apiStatus.Message, displayName)
			return
		}
	}
}
開發者ID:nsnt,項目名稱:cli,代碼行數:32,代碼來源:org_users.go

示例11: dumpResponse

func dumpResponse(res *http.Response) {
	dumpedResponse, err := httputil.DumpResponse(res, true)
	if err != nil {
		trace.Logger.Printf("Error dumping response\n%s\n", err)
	} else {
		trace.Logger.Printf("\n%s [%s]\n%s\n", terminal.HeaderColor("RESPONSE:"), time.Now().Format(time.RFC3339), Sanitize(string(dumpedResponse)))
	}
}
開發者ID:normalnorman,項目名稱:cli,代碼行數:8,代碼來源:http_client.go

示例12: dumpRequest

func dumpRequest(req *http.Request) {
	dumpedRequest, err := httputil.DumpRequest(req, true)
	if err != nil {
		fmt.Println("Error dumping request")
	} else {
		fmt.Printf("\n%s\n%s\n", term.HeaderColor("REQUEST:"), Sanitize(string(dumpedRequest)))
	}
}
開發者ID:jbayer,項目名稱:cli,代碼行數:8,代碼來源:client.go

示例13: dumpResponse

func dumpResponse(res *http.Response) {
	dumpedResponse, err := httputil.DumpResponse(res, true)
	if err != nil {
		trace.Logger.Printf("Error dumping response")
	} else {
		trace.Logger.Printf("\n%s\n%s\n", terminal.HeaderColor("RESPONSE:"), Sanitize(string(dumpedResponse)))
	}
}
開發者ID:jalateras,項目名稱:cli,代碼行數:8,代碼來源:http_client.go

示例14: ApplicationStart

func (cmd *Start) ApplicationStart(app cf.Application) (updatedApp cf.Application, err error) {
	if app.State == "started" {
		cmd.ui.Say(terminal.WarningColor("App " + app.Name + " is already started"))
		return
	}

	cmd.ui.Say("Starting app %s in org %s / space %s as %s...",
		terminal.EntityNameColor(app.Name),
		terminal.EntityNameColor(cmd.config.Organization.Name),
		terminal.EntityNameColor(cmd.config.Space.Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	updatedApp, apiResponse := cmd.appRepo.Start(app)
	if apiResponse.IsNotSuccessful() {
		cmd.ui.Failed(apiResponse.Message)
		return
	}

	cmd.ui.Ok()

	logChan := make(chan *logmessage.Message, 1000)
	go cmd.displayLogMessages(logChan)

	onConnect := func() {
		cmd.ui.Say("\n%s", terminal.HeaderColor("Staging..."))
	}

	stopLoggingChan := make(chan bool)
	go cmd.logRepo.TailLogsFor(app, onConnect, logChan, stopLoggingChan, 1)

	instances, apiResponse := cmd.appRepo.GetInstances(updatedApp)
	for apiResponse.IsNotSuccessful() {
		if apiResponse.ErrorCode != cf.APP_NOT_STAGED {
			cmd.ui.Say("")
			cmd.ui.Failed(apiResponse.Message)
			return
		}

		cmd.ui.Wait(1 * time.Second)
		instances, apiResponse = cmd.appRepo.GetInstances(updatedApp)
	}

	stopLoggingChan <- true

	cmd.ui.Say("")

	cmd.startTime = time.Now()

	for cmd.displayInstancesStatus(app, instances) {
		cmd.ui.Wait(1 * time.Second)
		instances, _ = cmd.appRepo.GetInstances(updatedApp)
	}
	return
}
開發者ID:jalateras,項目名稱:cli,代碼行數:55,代碼來源:start.go

示例15: dumpRequest

func dumpRequest(req *http.Request) {
	shouldDisplayBody := !strings.Contains(req.Header.Get("Content-Type"), "multipart/form-data")
	dumpedRequest, err := httputil.DumpRequest(req, shouldDisplayBody)
	if err != nil {
		trace.Logger.Print("Error dumping request")
	} else {
		trace.Logger.Printf("\n%s\n%s\n", terminal.HeaderColor("REQUEST:"), Sanitize(string(dumpedRequest)))
		if !shouldDisplayBody {
			trace.Logger.Println("[MULTIPART/FORM-DATA CONTENT HIDDEN]")
		}
	}
}
開發者ID:jalateras,項目名稱:cli,代碼行數:12,代碼來源:http_client.go


注:本文中的cf/terminal.HeaderColor函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。