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


Golang terminal.CommandColor函數代碼示例

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


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

示例1: Execute

func (req ApiEndpointRequirement) Execute() (success bool) {
	if req.config.ApiEndpoint() == "" {
		loginTip := terminal.CommandColor(fmt.Sprintf("%s login", cf.Name()))
		apiTip := terminal.CommandColor(fmt.Sprintf("%s api", cf.Name()))
		req.ui.Say("No API endpoint targeted. Use '%s' or '%s' to target an endpoint.", loginTip, apiTip)
		return false
	}
	return true
}
開發者ID:knolleary,項目名稱:cli,代碼行數:9,代碼來源:api_endpoint.go

示例2: loadConfig

func loadConfig(termUI terminal.UI, configRepo configuration.ConfigurationRepository) (config *configuration.Configuration) {
	config, err := configRepo.Get()
	if err != nil {
		termUI.Failed(fmt.Sprintf(
			"Error loading config. Please reset target (%s) and log in (%s).",
			terminal.CommandColor(fmt.Sprintf("%s target", cf.Name())),
			terminal.CommandColor(fmt.Sprintf("%s login", cf.Name())),
		))
		configRepo.Delete()
		os.Exit(1)
		return
	}
	return
}
開發者ID:jalateras,項目名稱:cli,代碼行數:14,代碼來源:cf.go

示例3: Run

func (cmd *SetEnv) Run(c *cli.Context) {
	varName := c.Args()[1]
	varValue := c.Args()[2]
	app := cmd.appReq.GetApplication()

	cmd.ui.Say("Setting env variable '%s' to '%s' for app %s in org %s / space %s as %s...",
		terminal.EntityNameColor(varName),
		terminal.EntityNameColor(varValue),
		terminal.EntityNameColor(app.Name),
		terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
		terminal.EntityNameColor(cmd.config.SpaceFields().Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	if len(app.EnvironmentVars) == 0 {
		app.EnvironmentVars = map[string]string{}
	}
	envParams := app.EnvironmentVars
	envParams[varName] = varValue

	_, apiErr := cmd.appRepo.Update(app.Guid, models.AppParams{EnvironmentVars: &envParams})

	if apiErr != nil {
		cmd.ui.Failed(apiErr.Error())
		return
	}

	cmd.ui.Ok()
	cmd.ui.Say("TIP: Use '%s' to ensure your env variable changes take effect", terminal.CommandColor(cf.Name()+" push"))
}
開發者ID:knolleary,項目名稱:cli,代碼行數:30,代碼來源:set_env.go

示例4: Run

func (cmd *BindService) Run(c *cli.Context) {
	app := cmd.appReq.GetApplication()
	serviceInstance := cmd.serviceInstanceReq.GetServiceInstance()

	cmd.ui.Say("Binding service %s to app %s in org %s / space %s as %s...",
		terminal.EntityNameColor(serviceInstance.Name),
		terminal.EntityNameColor(app.Name),
		terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
		terminal.EntityNameColor(cmd.config.SpaceFields().Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	err := cmd.BindApplication(app, serviceInstance)
	if err != nil {
		if err, ok := err.(errors.HttpError); ok && err.ErrorCode() == errors.APP_ALREADY_BOUND {
			cmd.ui.Ok()
			cmd.ui.Warn("App %s is already bound to %s.", app.Name, serviceInstance.Name)
			return
		} else {
			cmd.ui.Failed(err.Error())
		}
	}

	cmd.ui.Ok()
	cmd.ui.Say("TIP: Use '%s' to ensure your env variable changes take effect", terminal.CommandColor(cf.Name()+" push"))
}
開發者ID:nota-ja,項目名稱:cli,代碼行數:26,代碼來源:bind_service.go

示例5: Run

func (cmd *SetEnv) Run(c *cli.Context) {
	varName := c.Args()[1]
	varValue := c.Args()[2]
	app := cmd.appReq.GetApplication()

	cmd.ui.Say("Setting env variable '%s' to '%s' for app %s in org %s / space %s as %s...",
		terminal.EntityNameColor(varName),
		terminal.EntityNameColor(varValue),
		terminal.EntityNameColor(app.Name),
		terminal.EntityNameColor(cmd.config.OrganizationFields.Name),
		terminal.EntityNameColor(cmd.config.SpaceFields.Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	appParams := app.ToParams()
	envParams := appParams.Get("env").(generic.Map)
	envParams.Set(varName, varValue)

	updateParams := cf.NewEmptyAppParams()
	updateParams.Set("env", envParams)

	_, apiResponse := cmd.appRepo.Update(app.Guid, updateParams)

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

	cmd.ui.Ok()
	cmd.ui.Say("TIP: Use '%s' to ensure your env variable changes take effect", terminal.CommandColor(cf.Name()+" push"))
}
開發者ID:nsnt,項目名稱:cli,代碼行數:31,代碼來源:set_env.go

示例6: Execute

func (req TargetedSpaceRequirement) Execute() (success bool) {
	if !req.config.HasOrganization() {
		message := fmt.Sprintf("No org and space targeted. See '%s' to target an org and space.",
			terminal.CommandColor("cf target --o ORGNAME --s SPACENAME"))
		req.ui.Failed(message)
		return false
	}

	if !req.config.HasSpace() {
		message := fmt.Sprintf("No space targeted. Use '%s' to target a space.", terminal.CommandColor("cf target -s"))
		req.ui.Failed(message)
		return false
	}

	return true
}
開發者ID:jbayer,項目名稱:cli,代碼行數:16,代碼來源:targeted_space.go

示例7: Run

func (cmd *UnsetEnv) Run(c *cli.Context) {
	varName := c.Args()[1]
	app := cmd.appReq.GetApplication()

	cmd.ui.Say("Removing env variable %s from app %s in org %s / space %s as %s...",
		terminal.EntityNameColor(varName),
		terminal.EntityNameColor(app.Name),
		terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
		terminal.EntityNameColor(cmd.config.SpaceFields().Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	envParams := app.EnvironmentVars

	if _, ok := envParams[varName]; !ok {
		cmd.ui.Ok()
		cmd.ui.Warn("Env variable %s was not set.", varName)
		return
	}

	delete(envParams, varName)

	_, apiResponse := cmd.appRepo.Update(app.Guid, models.AppParams{EnvironmentVars: &envParams})
	if apiResponse.IsNotSuccessful() {
		cmd.ui.Failed(apiResponse.Message)
		return
	}

	cmd.ui.Ok()
	cmd.ui.Say("TIP: Use '%s' to ensure your env variable changes take effect", terminal.CommandColor(cf.Name()+" push"))
}
開發者ID:normalnorman,項目名稱:cli,代碼行數:31,代碼來源:unset_env.go

示例8: setApiEndpoint

func (cmd Api) setApiEndpoint(endpoint string, skipSSL bool) {
	if strings.HasSuffix(endpoint, "/") {
		endpoint = strings.TrimSuffix(endpoint, "/")
	}

	cmd.config.SetSSLDisabled(skipSSL)
	endpoint, err := cmd.endpointRepo.UpdateEndpoint(endpoint)

	if err != nil {
		cmd.config.SetApiEndpoint("")
		cmd.config.SetSSLDisabled(false)

		switch typedErr := err.(type) {
		case *errors.InvalidSSLCert:
			cfApiCommand := terminal.CommandColor(fmt.Sprintf("%s api --skip-ssl-validation", cf.Name()))
			tipMessage := fmt.Sprintf("TIP: Use '%s' to continue with an insecure API endpoint", cfApiCommand)
			cmd.ui.Failed("Invalid SSL Cert for %s\n%s", typedErr.URL, tipMessage)
		default:
			cmd.ui.Failed(typedErr.Error())
		}
	}

	if !strings.HasPrefix(endpoint, "https://") {
		cmd.ui.Say(terminal.WarningColor("Warning: Insecure http API endpoint detected: secure https API endpoints are recommended\n"))
	}
}
開發者ID:knolleary,項目名稱:cli,代碼行數:26,代碼來源:api.go

示例9: doLogin

func (l Login) doLogin(username, password string) (apiErr *net.ApiError) {
	apiErr = l.authenticator.Authenticate(username, password)
	if apiErr == nil {
		l.ui.Ok()
		l.ui.Say("Use '%s' to view or set your target organization and space", term.CommandColor("cf target"))
	}
	return
}
開發者ID:jbayer,項目名稱:cli,代碼行數:8,代碼來源:login.go

示例10: doLogin

func (cmd Authenticate) doLogin(username, password string) (apiResponse net.ApiResponse) {
	apiResponse = cmd.authenticator.Authenticate(username, password)
	if apiResponse.IsSuccessful() {
		cmd.ui.Ok()
		cmd.ui.Say("Use '%s' to view or set your target org and space", terminal.CommandColor(cf.Name()+" target"))
	}
	return
}
開發者ID:nsnt,項目名稱:cli,代碼行數:8,代碼來源:authenticate.go

示例11: Run

func (cmd CreateSpace) Run(c *cli.Context) {
	spaceName := c.Args()[0]
	orgName := c.String("o")
	orgGuid := ""
	if orgName == "" {
		orgName = cmd.config.OrganizationFields().Name
		orgGuid = cmd.config.OrganizationFields().Guid
	}

	cmd.ui.Say("Creating space %s in org %s as %s...",
		terminal.EntityNameColor(spaceName),
		terminal.EntityNameColor(orgName),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	if orgGuid == "" {
		org, apiErr := cmd.orgRepo.FindByName(orgName)
		switch apiErr.(type) {
		case nil:
		case errors.ModelNotFoundError:
			cmd.ui.Failed("Org %s does not exist or is not accessible", orgName)
			return
		default:
			cmd.ui.Failed("Error finding org %s\n%s", orgName, apiErr.Error())
			return
		}

		orgGuid = org.Guid
	}

	space, apiErr := cmd.spaceRepo.Create(spaceName, orgGuid)
	if apiErr != nil {
		if apiErr.ErrorCode() == cf.SPACE_EXISTS {
			cmd.ui.Ok()
			cmd.ui.Warn("Space %s already exists", spaceName)
			return
		}
		cmd.ui.Failed(apiErr.Error())
		return
	}
	cmd.ui.Ok()

	var err error

	err = cmd.spaceRoleSetter.SetSpaceRole(space, models.SPACE_MANAGER, cmd.config.UserGuid(), cmd.config.Username())
	if err != nil {
		cmd.ui.Failed(err.Error())
		return
	}

	err = cmd.spaceRoleSetter.SetSpaceRole(space, models.SPACE_DEVELOPER, cmd.config.UserGuid(), cmd.config.Username())
	if err != nil {
		cmd.ui.Failed(err.Error())
		return
	}

	cmd.ui.Say("\nTIP: Use '%s' to target new space", terminal.CommandColor(cf.Name()+" target -o "+orgName+" -s "+space.Name))
}
開發者ID:knolleary,項目名稱:cli,代碼行數:58,代碼來源:create_space.go

示例12: Execute

func (req targetedOrgApiRequirement) Execute() (success bool) {
	if !req.config.HasOrganization() {
		message := fmt.Sprintf("No org targeted, use '%s' to target an org.",
			terminal.CommandColor(cf.Name()+" target -o ORG"))
		req.ui.Failed(message)
		return false
	}

	return true
}
開發者ID:knolleary,項目名稱:cli,代碼行數:10,代碼來源:targeted_organization.go

示例13: Run

func (cmd Target) Run(c *cli.Context) {
	orgName := c.String("o")
	spaceName := c.String("s")
	shouldShowTarget := (orgName == "" && spaceName == "")

	if shouldShowTarget {
		cmd.ui.ShowConfiguration(cmd.config)

		if !cmd.config.HasOrganization() {
			cmd.ui.Say("No org targeted, use '%s' to target an org", terminal.CommandColor(cf.Name()+" target -o"))
		}
		if !cmd.config.HasSpace() {
			cmd.ui.Say("No space targeted, use '%s' to target a space", terminal.CommandColor(cf.Name()+" target -s"))
		}
		return
	}

	if orgName != "" {
		err := cmd.setOrganization(orgName)

		if spaceName == "" && cmd.config.IsLoggedIn() {
			cmd.showConfig()
			cmd.ui.Say("No space targeted, use '%s' to target a space", terminal.CommandColor(cf.Name()+" target -s"))
			return
		}

		if err != nil {
			return
		}
	}

	if spaceName != "" {
		err := cmd.setSpace(spaceName)

		if err != nil {
			return
		}
	}
	cmd.showConfig()
	return
}
開發者ID:nsnt,項目名稱:cli,代碼行數:41,代碼來源:target.go

示例14: Run

func (cmd CreateOrganization) Run(c *cli.Context) {
	name := c.Args()[0]

	cmd.ui.Say("Creating organization %s...", term.EntityNameColor(name))
	apiErr := cmd.orgRepo.Create(name)
	if apiErr != nil {
		cmd.ui.Failed(apiErr.Error())
		return
	}

	cmd.ui.Ok()
	cmd.ui.Say("\nTIP: Use '%s' to target new org.", term.CommandColor("cf target -o "+name))
}
開發者ID:jbayer,項目名稱:cli,代碼行數:13,代碼來源:create_org.go

示例15: Run

func (cmd CreateSpace) Run(c *cli.Context) {
	spaceName := c.Args()[0]
	cmd.ui.Say("Creating space %s...", term.EntityNameColor(spaceName))

	err := cmd.spaceRepo.Create(spaceName)
	if err != nil {
		cmd.ui.Failed(err.Error())
		return
	}

	cmd.ui.Ok()
	cmd.ui.Say("\nTIP: Use '%s' to target new space.", term.CommandColor("cf target -s "+spaceName))
}
開發者ID:jbayer,項目名稱:cli,代碼行數:13,代碼來源:create_space.go


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