本文整理匯總了Golang中cf.Name函數的典型用法代碼示例。如果您正苦於以下問題:Golang Name函數的具體用法?Golang Name怎麽用?Golang Name使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Name函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ShowConfiguration
func (ui terminalUI) ShowConfiguration(config configuration.Reader) {
if config.HasAPIEndpoint() {
ui.Say("API endpoint: %s (API version: %s)",
EntityNameColor(config.ApiEndpoint()),
EntityNameColor(config.ApiVersion()))
}
if !config.IsLoggedIn() {
ui.Say(NotLoggedInText())
return
} else {
ui.Say("User: %s", EntityNameColor(config.UserEmail()))
}
if !config.HasOrganization() && !config.HasSpace() {
command := fmt.Sprintf("%s target -o ORG -s SPACE", cf.Name())
ui.Say("No org or space targeted, use '%s'", CommandColor(command))
return
}
if config.HasOrganization() {
ui.Say("Org: %s", EntityNameColor(config.OrganizationFields().Name))
} else {
command := fmt.Sprintf("%s target -o Org", cf.Name())
ui.Say("Org: No org targeted, use '%s'", CommandColor(command))
}
if config.HasSpace() {
ui.Say("Space: %s", EntityNameColor(config.SpaceFields().Name))
} else {
command := fmt.Sprintf("%s target -s SPACE", cf.Name())
ui.Say("Space: No space targeted, use '%s'", CommandColor(command))
}
}
示例2: 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
}
示例3: 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
}
示例4: Run
func (cmd *DeleteSpace) Run(c *cli.Context) {
spaceName := c.Args()[0]
if !c.Bool("f") {
if !cmd.ui.ConfirmDelete("space", spaceName) {
return
}
}
cmd.ui.Say("Deleting space %s in org %s as %s...",
terminal.EntityNameColor(spaceName),
terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
terminal.EntityNameColor(cmd.config.Username()),
)
space := cmd.spaceReq.GetSpace()
apiErr := cmd.spaceRepo.Delete(space.Guid)
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
return
}
cmd.ui.Ok()
if cmd.config.SpaceFields().Name == spaceName {
cmd.config.SetSpaceFields(models.SpaceFields{})
cmd.ui.Say("TIP: No space targeted, use '%s target -s' to target a space", cf.Name())
}
return
}
示例5: setSpace
func (cmd Target) setSpace(spaceName string) (err error) {
if !cmd.config.IsLoggedIn() {
cmd.ui.Failed("You must be logged in to set a space. Use '%s login'.", cf.Name())
return
}
if !cmd.config.HasOrganization() {
cmd.ui.Failed("An org must be targeted before targeting a space")
return
}
space, apiResponse := cmd.spaceRepo.FindByName(spaceName)
if apiResponse.IsNotSuccessful() {
cmd.ui.Failed("Unable to access space %s.\n%s", spaceName, apiResponse.Message)
return
}
err = cmd.configRepo.SetSpace(space.SpaceFields)
if err != nil {
cmd.ui.Failed("Error setting space in config file.\n%s", err)
return
}
return
}
示例6: 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"))
}
}
示例7: displayCrashDialog
func displayCrashDialog() {
formattedString := `
d8888 888 888 888 888 .d8888b. 888 888 888 888 .d8888b. 888 d8P .d8888b.
d88888 888 o 888 888 o 888 d88P Y88b 888 888 888 888 d88P Y88b 888 d8P d88P Y88b
d88P888 888 d8b 888 888 d8b 888 Y88b. 888 888 888 888 888 888 888 d8P Y88b.
d88P 888 888 d888b 888 888 d888b 888 "Y888b. 8888888888 888 888 888 888d88K "Y888b.
d88P 888 888d88888b888 888d88888b888 "Y88b. 888 888 888 888 888 8888888b "Y88b.
d88P 888 88888P Y88888 88888P Y88888 "888 888 888 888 888 888 888 888 Y88b "888
d8888888888 8888P Y8888 8888P Y8888 Y88b d88P 888 888 Y88b. .d88P Y88b d88P 888 Y88b Y88b d88P d8b
d88P 888 888P Y888 888P Y888 "Y8888P" 888 888 "Y88888P" "Y8888P" 888 Y88b "Y8888P" Y8P
Something completely unexpected happened. This is a bug in %s.
Please file this bug : https://github.com/cloudfoundry/cli/issues
Tell us that you ran this command:
%s
and got this stack trace:
%s
`
stackTrace := "\t" + strings.Replace(string(debug.Stack()), "\n", "\n\t", -1)
println(fmt.Sprintf(formattedString, cf.Name(), strings.Join(os.Args, " "), stackTrace))
os.Exit(1)
}
示例8: 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.(cferrors.HttpError); ok && err.ErrorCode() == AppAlreadyBoundErrorCode {
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 push' to ensure your env variable changes take effect", cf.Name())
}
示例9: 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()),
)
apiResponse := cmd.BindApplication(app, serviceInstance)
if apiResponse.IsNotSuccessful() && apiResponse.ErrorCode != AppAlreadyBoundErrorCode {
cmd.ui.Failed(apiResponse.Message)
}
cmd.ui.Ok()
if apiResponse.ErrorCode == AppAlreadyBoundErrorCode {
cmd.ui.Warn("App %s is already bound to %s.", app.Name, serviceInstance.Name)
return
}
cmd.ui.Say("TIP: Use '%s push' to ensure your env variable changes take effect", cf.Name())
}
示例10: 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.Organization.Name),
terminal.EntityNameColor(cmd.config.Space.Name),
terminal.EntityNameColor(cmd.config.Username()),
)
envVars := app.EnvironmentVars
if !envVarFound(varName, envVars) {
cmd.ui.Ok()
cmd.ui.Warn("Env variable %s was not set.", varName)
return
}
delete(envVars, varName)
apiResponse := cmd.appRepo.SetEnv(app, envVars)
if apiResponse.IsNotSuccessful() {
cmd.ui.Failed(apiResponse.Message)
return
}
cmd.ui.Ok()
cmd.ui.Say("TIP: Use '%s push' to ensure your env variable changes take effect", cf.Name())
}
示例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))
}
示例12: Run
func (cmd *DeleteSpace) Run(c *cli.Context) {
spaceName := c.Args()[0]
force := c.Bool("f")
cmd.ui.Say("Deleting space %s in org %s as %s...",
terminal.EntityNameColor(spaceName),
terminal.EntityNameColor(cmd.config.Organization.Name),
terminal.EntityNameColor(cmd.config.Username()),
)
space, apiResponse := cmd.spaceRepo.FindByName(spaceName)
if apiResponse.IsError() {
cmd.ui.Failed(apiResponse.Message)
return
}
if apiResponse.IsNotFound() {
cmd.ui.Ok()
cmd.ui.Warn("Space %s does not exist.", spaceName)
return
}
if !force {
response := cmd.ui.Confirm(
"Really delete space %s and everything associated with it?%s",
terminal.EntityNameColor(spaceName),
terminal.PromptColor(">"),
)
if !response {
return
}
}
apiResponse = cmd.spaceRepo.Delete(space)
if apiResponse.IsNotSuccessful() {
cmd.ui.Failed(apiResponse.Message)
return
}
cmd.ui.Ok()
config, err := cmd.configRepo.Get()
if err != nil {
cmd.ui.ConfigFailure(err)
return
}
if config.Space.Name == spaceName {
config.Space = cf.Space{}
cmd.configRepo.Save()
cmd.ui.Say("TIP: No space targeted, use '%s target -s' to target a space", cf.Name())
}
return
}
示例13: 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
}
示例14: 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 target -o' to target an org", cf.Name())
}
if !cmd.config.HasSpace() {
cmd.ui.Say("No space targeted, use '%s target -s' to target a space", cf.Name())
}
return
}
if orgName != "" {
err := cmd.setOrganization(orgName)
if spaceName == "" && cmd.config.IsLoggedIn() {
cmd.showConfig()
cmd.ui.Say("No space targeted, use '%s target -s' to target a space", cf.Name())
return
}
if err != nil {
return
}
}
if spaceName != "" {
err := cmd.setSpace(spaceName)
if err != nil {
return
}
}
cmd.showConfig()
return
}
示例15: getCommand
func getCommand(metadata command_metadata.CommandMetadata, runner command_runner.Runner) cli.Command {
return cli.Command{
Name: metadata.Name,
ShortName: metadata.ShortName,
Description: metadata.Description,
Usage: strings.Replace(metadata.Usage, "CF_NAME", cf.Name(), -1),
Action: func(context *cli.Context) {
runner.RunCmdByName(metadata.Name, context)
},
Flags: metadata.Flags,
}
}