本文整理匯總了Golang中code/cloudfoundry/org/cli/cf/flags.FlagContext.String方法的典型用法代碼示例。如果您正苦於以下問題:Golang FlagContext.String方法的具體用法?Golang FlagContext.String怎麽用?Golang FlagContext.String使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類code/cloudfoundry/org/cli/cf/flags.FlagContext
的用法示例。
在下文中一共展示了FlagContext.String方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Execute
func (cmd *CreateServiceKey) Execute(c flags.FlagContext) error {
serviceInstance := cmd.serviceInstanceRequirement.GetServiceInstance()
serviceKeyName := c.Args()[1]
params := c.String("c")
paramsMap, err := json.ParseJSONFromFileOrString(params)
if err != nil {
return errors.New(T("Invalid configuration provided for -c flag. Please provide a valid JSON object or path to a file containing a valid JSON object."))
}
cmd.ui.Say(T("Creating service key {{.ServiceKeyName}} for service instance {{.ServiceInstanceName}} as {{.CurrentUser}}...",
map[string]interface{}{
"ServiceInstanceName": terminal.EntityNameColor(serviceInstance.Name),
"ServiceKeyName": terminal.EntityNameColor(serviceKeyName),
"CurrentUser": terminal.EntityNameColor(cmd.config.Username()),
}))
err = cmd.serviceKeyRepo.CreateServiceKey(serviceInstance.GUID, serviceKeyName, paramsMap)
switch err.(type) {
case nil:
cmd.ui.Ok()
case *errors.ModelAlreadyExistsError:
cmd.ui.Ok()
cmd.ui.Warn(err.Error())
default:
return err
}
return nil
}
示例2: Execute
func (cmd *MapRoute) Execute(c flags.FlagContext) error {
hostName := c.String("n")
path := c.String("path")
domain := cmd.domainReq.GetDomain()
app := cmd.appReq.GetApplication()
port := c.Int("port")
randomPort := c.Bool("random-port")
route, err := cmd.routeCreator.CreateRoute(hostName, path, port, randomPort, domain, cmd.config.SpaceFields())
if err != nil {
return errors.New(T("Error resolving route:\n{{.Err}}", map[string]interface{}{"Err": err.Error()}))
}
cmd.ui.Say(T("Adding route {{.URL}} to app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...",
map[string]interface{}{
"URL": terminal.EntityNameColor(route.URL()),
"AppName": terminal.EntityNameColor(app.Name),
"OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
"SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name),
"Username": terminal.EntityNameColor(cmd.config.Username())}))
err = cmd.routeRepo.Bind(route.GUID, app.GUID)
if err != nil {
return err
}
cmd.ui.Ok()
return nil
}
示例3: Execute
func (cmd *EnableServiceAccess) Execute(c flags.FlagContext) error {
_, err := cmd.tokenRefresher.RefreshAuthToken()
if err != nil {
return err
}
serviceName := c.Args()[0]
planName := c.String("p")
orgName := c.String("o")
if planName != "" && orgName != "" {
err = cmd.enablePlanAndOrgForService(serviceName, planName, orgName)
} else if planName != "" {
err = cmd.enablePlanForService(serviceName, planName)
} else if orgName != "" {
err = cmd.enableAllPlansForSingleOrgForService(serviceName, orgName)
} else {
err = cmd.enableAllPlansForService(serviceName)
}
if err != nil {
return err
}
cmd.ui.Ok()
return nil
}
示例4: Requirements
func (cmd *Push) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) ([]requirements.Requirement, error) {
var reqs []requirements.Requirement
usageReq := requirementsFactory.NewUsageRequirement(commandregistry.CLICommandUsagePresenter(cmd), "",
func() bool {
return len(fc.Args()) > 1
},
)
reqs = append(reqs, usageReq)
if fc.String("route-path") != "" {
reqs = append(reqs, requirementsFactory.NewMinAPIVersionRequirement("Option '--route-path'", cf.RoutePathMinimumAPIVersion))
}
if fc.String("app-ports") != "" {
reqs = append(reqs, requirementsFactory.NewMinAPIVersionRequirement("Option '--app-ports'", cf.MultipleAppPortsMinimumAPIVersion))
}
reqs = append(reqs, []requirements.Requirement{
requirementsFactory.NewLoginRequirement(),
requirementsFactory.NewTargetedSpaceRequirement(),
}...)
return reqs, nil
}
示例5: Requirements
func (cmd *UnmapRoute) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) ([]requirements.Requirement, error) {
if len(fc.Args()) != 2 {
cmd.ui.Failed(T("Incorrect Usage. Requires app_name, domain_name as arguments\n\n") + commandregistry.Commands.CommandUsage("unmap-route"))
return nil, fmt.Errorf("Incorrect usage: %d arguments of %d required", len(fc.Args()), 2)
}
if fc.IsSet("port") && (fc.IsSet("hostname") || fc.IsSet("path")) {
cmd.ui.Failed(T("Cannot specify port together with hostname and/or path."))
return nil, fmt.Errorf("Cannot specify port together with hostname and/or path.")
}
domainName := fc.Args()[1]
cmd.appReq = requirementsFactory.NewApplicationRequirement(fc.Args()[0])
cmd.domainReq = requirementsFactory.NewDomainRequirement(domainName)
var reqs []requirements.Requirement
if fc.String("path") != "" {
reqs = append(reqs, requirementsFactory.NewMinAPIVersionRequirement("Option '--path'", cf.RoutePathMinimumAPIVersion))
}
if fc.IsSet("port") {
reqs = append(reqs, requirementsFactory.NewMinAPIVersionRequirement("Option '--port'", cf.TCPRoutingMinimumAPIVersion))
}
reqs = append(reqs, []requirements.Requirement{
requirementsFactory.NewLoginRequirement(),
cmd.appReq,
cmd.domainReq,
}...)
return reqs, nil
}
示例6: Execute
func (cmd *Target) Execute(c flags.FlagContext) error {
orgName := c.String("o")
spaceName := c.String("s")
if orgName != "" {
err := cmd.setOrganization(orgName)
if err != nil {
return err
} else if spaceName == "" {
spaceList, apiErr := cmd.getSpaceList()
if apiErr == nil && len(spaceList) == 1 {
cmd.setSpace(spaceList[0].Name)
}
}
}
if spaceName != "" {
err := cmd.setSpace(spaceName)
if err != nil {
return err
}
}
err := cmd.ui.ShowConfiguration(cmd.config)
if err != nil {
return err
}
cmd.ui.NotifyUpdateIfNeeded(cmd.config)
if !cmd.config.IsLoggedIn() {
return fmt.Errorf(terminal.NotLoggedInText())
}
return nil
}
示例7: setOrganization
func (cmd Login) setOrganization(c flags.FlagContext) (bool, error) {
orgName := c.String("o")
if orgName == "" {
orgs, err := cmd.orgRepo.ListOrgs(maxChoices)
if err != nil {
return false, errors.New(T("Error finding available orgs\n{{.APIErr}}",
map[string]interface{}{"APIErr": err.Error()}))
}
switch len(orgs) {
case 0:
return false, nil
case 1:
cmd.targetOrganization(orgs[0])
return true, nil
default:
orgName = cmd.promptForOrgName(orgs)
if orgName == "" {
cmd.ui.Say("")
return false, nil
}
}
}
org, err := cmd.orgRepo.FindByName(orgName)
if err != nil {
return false, errors.New(T("Error finding org {{.OrgName}}\n{{.Err}}",
map[string]interface{}{"OrgName": terminal.EntityNameColor(orgName), "Err": err.Error()}))
}
cmd.targetOrganization(org)
return true, nil
}
示例8: Execute
func (cmd *UnbindRouteService) Execute(c flags.FlagContext) error {
var port int
host := c.String("hostname")
domain := cmd.domainReq.GetDomain()
path := c.String("path")
if !strings.HasPrefix(path, "/") && len(path) > 0 {
path = fmt.Sprintf("/%s", path)
}
route, err := cmd.routeRepo.Find(host, domain, path, port)
if err != nil {
return err
}
serviceInstance := cmd.serviceInstanceReq.GetServiceInstance()
confirmed := c.Bool("f")
if !confirmed {
confirmed = cmd.ui.Confirm(T("Unbinding may leave apps mapped to route {{.URL}} vulnerable; e.g. if service instance {{.ServiceInstanceName}} provides authentication. Do you want to proceed?",
map[string]interface{}{
"URL": route.URL(),
"ServiceInstanceName": serviceInstance.Name,
}))
if !confirmed {
cmd.ui.Warn(T("Unbind cancelled"))
return nil
}
}
cmd.ui.Say(T("Unbinding route {{.URL}} from service instance {{.ServiceInstanceName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.CurrentUser}}...",
map[string]interface{}{
"ServiceInstanceName": terminal.EntityNameColor(serviceInstance.Name),
"URL": terminal.EntityNameColor(route.URL()),
"OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
"SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name),
"CurrentUser": terminal.EntityNameColor(cmd.config.Username()),
}))
err = cmd.UnbindRoute(route, serviceInstance)
if err != nil {
httpError, ok := err.(errors.HTTPError)
if ok && httpError.ErrorCode() == errors.InvalidRelation {
cmd.ui.Warn(T("Route {{.Route}} was not bound to service instance {{.ServiceInstance}}.", map[string]interface{}{"Route": route.URL(), "ServiceInstance": serviceInstance.Name}))
} else {
return err
}
}
cmd.ui.Ok()
return nil
}
示例9: Requirements
func (cmd *MapRoute) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) ([]requirements.Requirement, error) {
if len(fc.Args()) != 2 {
cmd.ui.Failed(T("Incorrect Usage. Requires APP_NAME and DOMAIN as arguments\n\n") + commandregistry.Commands.CommandUsage("map-route"))
return nil, fmt.Errorf("Incorrect usage: %d arguments of %d required", len(fc.Args()), 2)
}
if fc.IsSet("port") && (fc.IsSet("hostname") || fc.IsSet("path")) {
cmd.ui.Failed(T("Cannot specify port together with hostname and/or path."))
return nil, fmt.Errorf("Cannot specify port together with hostname and/or path.")
}
if fc.IsSet("random-port") && (fc.IsSet("port") || fc.IsSet("hostname") || fc.IsSet("path")) {
cmd.ui.Failed(T("Cannot specify random-port together with port, hostname and/or path."))
return nil, fmt.Errorf("Cannot specify random-port together with port, hostname and/or path.")
}
appName := fc.Args()[0]
domainName := fc.Args()[1]
requirement := requirementsFactory.NewApplicationRequirement(appName)
cmd.appReq = requirement
cmd.domainReq = requirementsFactory.NewDomainRequirement(domainName)
var reqs []requirements.Requirement
if fc.String("path") != "" {
reqs = append(reqs, requirementsFactory.NewMinAPIVersionRequirement("Option '--path'", cf.RoutePathMinimumAPIVersion))
}
var flag string
switch {
case fc.IsSet("port"):
flag = "port"
case fc.IsSet("random-port"):
flag = "random-port"
}
if flag != "" {
reqs = append(reqs, requirementsFactory.NewMinAPIVersionRequirement(fmt.Sprintf("Option '--%s'", flag), cf.TCPRoutingMinimumAPIVersion))
reqs = append(reqs, requirementsFactory.NewDiegoApplicationRequirement(appName))
}
reqs = append(reqs, []requirements.Requirement{
requirementsFactory.NewLoginRequirement(),
cmd.appReq,
cmd.domainReq,
}...)
return reqs, nil
}
示例10: Execute
func (cmd *CreateService) Execute(c flags.FlagContext) error {
serviceName := c.Args()[0]
planName := c.Args()[1]
serviceInstanceName := c.Args()[2]
params := c.String("c")
tags := c.String("t")
tagsList := uihelpers.ParseTags(tags)
paramsMap, err := json.ParseJSONFromFileOrString(params)
if err != nil {
return errors.New(T("Invalid configuration provided for -c flag. Please provide a valid JSON object or path to a file containing a valid JSON object."))
}
cmd.ui.Say(T("Creating service instance {{.ServiceName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.CurrentUser}}...",
map[string]interface{}{
"ServiceName": terminal.EntityNameColor(serviceInstanceName),
"OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
"SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name),
"CurrentUser": terminal.EntityNameColor(cmd.config.Username()),
}))
plan, err := cmd.CreateService(serviceName, planName, serviceInstanceName, paramsMap, tagsList)
switch err.(type) {
case nil:
err := printSuccessMessageForServiceInstance(serviceInstanceName, cmd.serviceRepo, cmd.ui)
if err != nil {
return err
}
if !plan.Free {
cmd.ui.Say("")
cmd.ui.Say(T("Attention: The plan `{{.PlanName}}` of service `{{.ServiceName}}` is not free. The instance `{{.ServiceInstanceName}}` will incur a cost. Contact your administrator if you think this is in error.",
map[string]interface{}{
"PlanName": terminal.EntityNameColor(plan.Name),
"ServiceName": terminal.EntityNameColor(serviceName),
"ServiceInstanceName": terminal.EntityNameColor(serviceInstanceName),
}))
cmd.ui.Say("")
}
case *errors.ModelAlreadyExistsError:
cmd.ui.Ok()
cmd.ui.Warn(err.Error())
default:
return err
}
return nil
}
示例11: Execute
func (cmd *CreateRoute) Execute(c flags.FlagContext) error {
hostName := c.String("n")
space := cmd.spaceReq.GetSpace()
domain := cmd.domainReq.GetDomain()
path := c.String("path")
port := c.Int("port")
randomPort := c.Bool("random-port")
_, err := cmd.CreateRoute(hostName, path, port, randomPort, domain, space.SpaceFields)
if err != nil {
return err
}
return nil
}
示例12: Execute
func (cmd *MarketplaceServices) Execute(c flags.FlagContext) error {
serviceName := c.String("s")
var err error
if serviceName != "" {
err = cmd.marketplaceByService(serviceName)
} else {
err = cmd.marketplace()
}
if err != nil {
return err
}
return nil
}
示例13: Execute
func (cmd *PurgeServiceOffering) Execute(c flags.FlagContext) error {
serviceName := c.Args()[0]
var offering models.ServiceOffering
if c.IsSet("p") {
var err error
offering, err = cmd.serviceRepo.FindServiceOfferingByLabelAndProvider(serviceName, c.String("p"))
if err != nil {
if _, ok := err.(*errors.ModelNotFoundError); ok {
cmd.ui.Warn(T("Service offering does not exist\nTIP: If you are trying to purge a v1 service offering, you must set the -p flag."))
return nil
}
return err
}
} else {
offerings, err := cmd.serviceRepo.FindServiceOfferingsByLabel(serviceName)
if err != nil {
if _, ok := err.(*errors.ModelNotFoundError); ok {
cmd.ui.Warn(T("Service offering does not exist\nTIP: If you are trying to purge a v1 service offering, you must set the -p flag."))
return nil
}
return err
}
offering = offerings[0]
}
confirmed := c.Bool("f")
if !confirmed {
cmd.ui.Warn(scaryWarningMessage())
confirmed = cmd.ui.Confirm(T("Really purge service offering {{.ServiceName}} from Cloud Foundry?",
map[string]interface{}{"ServiceName": serviceName},
))
}
if !confirmed {
return nil
}
cmd.ui.Say(T("Purging service {{.ServiceName}}...", map[string]interface{}{"ServiceName": serviceName}))
err := cmd.serviceRepo.PurgeServiceOffering(offering)
if err != nil {
return err
}
cmd.ui.Ok()
return nil
}
示例14: decideEndpoint
func (cmd Login) decideEndpoint(c flags.FlagContext) (string, bool) {
endpoint := c.String("a")
skipSSL := c.Bool("skip-ssl-validation")
if endpoint == "" {
endpoint = cmd.config.APIEndpoint()
skipSSL = cmd.config.IsSSLDisabled() || skipSSL
}
if endpoint == "" {
endpoint = cmd.ui.Ask(T("API endpoint"))
} else {
cmd.ui.Say(T("API endpoint: {{.Endpoint}}", map[string]interface{}{"Endpoint": terminal.EntityNameColor(endpoint)}))
}
return endpoint, skipSSL
}
示例15: Requirements
func (cmd *CreateSpace) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) ([]requirements.Requirement, error) {
if len(fc.Args()) != 1 {
cmd.ui.Failed(T("Incorrect Usage. Requires an argument\n\n") + commandregistry.Commands.CommandUsage("create-space"))
return nil, fmt.Errorf("Incorrect usage: %d arguments of %d required", len(fc.Args()), 1)
}
reqs := []requirements.Requirement{
requirementsFactory.NewLoginRequirement(),
}
if fc.String("o") == "" {
reqs = append(reqs, requirementsFactory.NewTargetedOrgRequirement())
}
return reqs, nil
}