本文整理汇总了Golang中github.com/simonleung8/flags.FlagContext.String方法的典型用法代码示例。如果您正苦于以下问题:Golang FlagContext.String方法的具体用法?Golang FlagContext.String怎么用?Golang FlagContext.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/simonleung8/flags.FlagContext
的用法示例。
在下文中一共展示了FlagContext.String方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Requirements
func (cmd *CreateRoute) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) ([]requirements.Requirement, error) {
if len(fc.Args()) != 2 {
cmd.ui.Failed(T("Incorrect Usage. Requires SPACE and DOMAIN as arguments\n\n") + command_registry.Commands.CommandUsage("create-route"))
}
domainName := fc.Args()[1]
cmd.spaceReq = requirementsFactory.NewSpaceRequirement(fc.Args()[0])
cmd.domainReq = requirementsFactory.NewDomainRequirement(domainName)
reqs := []requirements.Requirement{
requirementsFactory.NewLoginRequirement(),
requirementsFactory.NewTargetedOrgRequirement(),
cmd.spaceReq,
cmd.domainReq,
}
if fc.String("path") != "" {
minRequiredAPIVersion, err := semver.Make("2.36.0")
if err != nil {
panic(err.Error())
}
reqs = append(reqs, requirementsFactory.NewMinAPIVersionRequirement("create-route", minRequiredAPIVersion))
}
return reqs, nil
}
示例2: Execute
func (cmd *CreateUserProvidedService) Execute(c flags.FlagContext) {
name := c.Args()[0]
drainUrl := c.String("l")
params := c.String("p")
params = strings.Trim(params, `"`)
paramsMap := make(map[string]interface{})
err := json.Unmarshal([]byte(params), ¶msMap)
if err != nil && params != "" {
paramsMap = cmd.mapValuesFromPrompt(params, paramsMap)
}
cmd.ui.Say(T("Creating user provided service {{.ServiceName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.CurrentUser}}...",
map[string]interface{}{
"ServiceName": terminal.EntityNameColor(name),
"OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
"SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name),
"CurrentUser": terminal.EntityNameColor(cmd.config.Username()),
}))
apiErr := cmd.userProvidedServiceInstanceRepo.Create(name, drainUrl, paramsMap)
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
return
}
cmd.ui.Ok()
}
示例3: Execute
func (cmd *CreateQuota) Execute(context flags.FlagContext) {
name := context.Args()[0]
cmd.ui.Say(T("Creating quota {{.QuotaName}} as {{.Username}}...", map[string]interface{}{
"QuotaName": terminal.EntityNameColor(name),
"Username": terminal.EntityNameColor(cmd.config.Username()),
}))
quota := models.QuotaFields{
Name: name,
}
memoryLimit := context.String("m")
if memoryLimit != "" {
parsedMemory, err := formatters.ToMegabytes(memoryLimit)
if err != nil {
cmd.ui.Failed(T("Invalid memory limit: {{.MemoryLimit}}\n{{.Err}}", map[string]interface{}{"MemoryLimit": memoryLimit, "Err": err}))
}
quota.MemoryLimit = parsedMemory
}
instanceMemoryLimit := context.String("i")
if instanceMemoryLimit == "-1" || instanceMemoryLimit == "" {
quota.InstanceMemoryLimit = -1
} else {
parsedMemory, errr := formatters.ToMegabytes(instanceMemoryLimit)
if errr != nil {
cmd.ui.Failed(T("Invalid instance memory limit: {{.MemoryLimit}}\n{{.Err}}", map[string]interface{}{"MemoryLimit": instanceMemoryLimit, "Err": errr}))
}
quota.InstanceMemoryLimit = parsedMemory
}
if context.IsSet("r") {
quota.RoutesLimit = context.Int("r")
}
if context.IsSet("s") {
quota.ServicesLimit = context.Int("s")
}
if context.IsSet("allow-paid-service-plans") {
quota.NonBasicServicesAllowed = true
}
err := cmd.quotaRepo.Create(quota)
httpErr, ok := err.(errors.HttpError)
if ok && httpErr.ErrorCode() == errors.QUOTA_EXISTS {
cmd.ui.Ok()
cmd.ui.Warn(T("Quota Definition {{.QuotaName}} already exists", map[string]interface{}{"QuotaName": quota.Name}))
return
}
if err != nil {
cmd.ui.Failed(err.Error())
}
cmd.ui.Ok()
}
示例4: Execute
func (cmd *MapRoute) Execute(c flags.FlagContext) {
hostName := c.String("n")
domain := cmd.domainReq.GetDomain()
app := cmd.appReq.GetApplication()
route, apiErr := cmd.routeCreator.CreateRoute(hostName, domain, cmd.config.SpaceFields())
if apiErr != nil {
cmd.ui.Failed(T("Error resolving route:\n{{.Err}}", map[string]interface{}{"Err": apiErr.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())}))
apiErr = cmd.routeRepo.Bind(route.Guid, app.Guid)
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
return
}
cmd.ui.Ok()
}
示例5: Execute
func (cmd *UnmapRoute) Execute(c flags.FlagContext) {
hostName := c.String("n")
domain := cmd.domainReq.GetDomain()
app := cmd.appReq.GetApplication()
route, apiErr := cmd.routeRepo.FindByHostAndDomain(hostName, domain)
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
}
cmd.ui.Say(T("Removing route {{.URL}} from 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())}))
var routeFound bool
for _, routeApp := range route.Apps {
if routeApp.Guid == app.Guid {
routeFound = true
apiErr = cmd.routeRepo.Unbind(route.Guid, app.Guid)
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
return
}
}
}
cmd.ui.Ok()
if !routeFound {
cmd.ui.Warn(T("\nRoute to be unmapped is not currently mapped to the application."))
}
}
示例6: Execute
func (cmd *CreateServiceKey) Execute(c flags.FlagContext) {
serviceInstance := cmd.serviceInstanceRequirement.GetServiceInstance()
serviceKeyName := c.Args()[1]
params := c.String("c")
paramsMap, err := json.ParseJsonFromFileOrString(params)
if err != nil {
cmd.ui.Failed(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:
cmd.ui.Failed(err.Error())
}
}
示例7: Execute
func (cmd *Target) Execute(c flags.FlagContext) {
orgName := c.String("o")
spaceName := c.String("s")
if orgName != "" {
err := cmd.setOrganization(orgName)
if err != nil {
cmd.ui.Failed(err.Error())
} 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 {
cmd.ui.Failed(err.Error())
}
}
cmd.ui.ShowConfiguration(cmd.config)
if !cmd.config.IsLoggedIn() {
cmd.ui.PanicQuietly()
}
cmd.ui.NotifyUpdateIfNeeded(cmd.config)
return
}
示例8: Execute
func (cmd *CreateOrg) Execute(c flags.FlagContext) {
name := c.Args()[0]
cmd.ui.Say(T("Creating org {{.OrgName}} as {{.Username}}...",
map[string]interface{}{
"OrgName": terminal.EntityNameColor(name),
"Username": terminal.EntityNameColor(cmd.config.Username())}))
org := models.Organization{OrganizationFields: models.OrganizationFields{Name: name}}
quotaName := c.String("q")
if quotaName != "" {
quota, err := cmd.quotaRepo.FindByName(quotaName)
if err != nil {
cmd.ui.Failed(err.Error())
}
org.QuotaDefinition.Guid = quota.Guid
}
err := cmd.orgRepo.Create(org)
if err != nil {
if apiErr, ok := err.(errors.HttpError); ok && apiErr.ErrorCode() == errors.ORG_EXISTS {
cmd.ui.Ok()
cmd.ui.Warn(T("Org {{.OrgName}} already exists",
map[string]interface{}{"OrgName": name}))
return
} else {
cmd.ui.Failed(err.Error())
}
}
cmd.ui.Ok()
cmd.ui.Say(T("\nTIP: Use '{{.Command}}' to target new org",
map[string]interface{}{"Command": terminal.CommandColor(cf.Name() + " target -o " + name)}))
}
示例9: Execute
func (cmd *RepoPlugins) Execute(c flags.FlagContext) {
var repos []models.PluginRepo
repoName := c.String("r")
repos = cmd.config.PluginRepos()
if repoName == "" {
cmd.ui.Say(T("Getting plugins from all repositories ... "))
} else {
index := cmd.findRepoIndex(repoName)
if index != -1 {
cmd.ui.Say(T("Getting plugins from repository '") + repoName + "' ...")
repos = []models.PluginRepo{repos[index]}
} else {
cmd.ui.Failed(repoName + T(" does not exist as an available plugin repo."+"\nTip: use `add-plugin-repo` command to add repos."))
}
}
cmd.ui.Say("")
repoPlugins, repoError := cmd.pluginRepo.GetPlugins(repos)
cmd.printTable(repoPlugins)
cmd.printErrors(repoError)
}
示例10: authenticate
func (cmd Login) authenticate(c flags.FlagContext) {
usernameFlagValue := c.String("u")
passwordFlagValue := c.String("p")
prompts, err := cmd.authenticator.GetLoginPromptsAndSaveUAAServerURL()
if err != nil {
cmd.ui.Failed(err.Error())
}
passwordKeys := []string{}
credentials := make(map[string]string)
if value, ok := prompts["username"]; ok {
if prompts["username"].Type == core_config.AuthPromptTypeText && usernameFlagValue != "" {
credentials["username"] = usernameFlagValue
} else {
credentials["username"] = cmd.ui.Ask("%s", value.DisplayName)
}
}
for key, prompt := range prompts {
if prompt.Type == core_config.AuthPromptTypePassword {
if key == "passcode" {
continue
}
passwordKeys = append(passwordKeys, key)
} else if key == "username" {
continue
} else {
credentials[key] = cmd.ui.Ask("%s", prompt.DisplayName)
}
}
for i := 0; i < maxLoginTries; i++ {
for _, key := range passwordKeys {
if key == "password" && passwordFlagValue != "" {
credentials[key] = passwordFlagValue
passwordFlagValue = ""
} else {
credentials[key] = cmd.ui.AskForPassword("%s", prompts[key].DisplayName)
}
}
cmd.ui.Say(T("Authenticating..."))
err = cmd.authenticator.Authenticate(credentials)
if err == nil {
cmd.ui.Ok()
cmd.ui.Say("")
break
}
cmd.ui.Say(err.Error())
}
if err != nil {
cmd.ui.Failed(T("Unable to authenticate."))
}
}
示例11: Execute
func (cmd *MarketplaceServices) Execute(c flags.FlagContext) {
serviceName := c.String("s")
if serviceName != "" {
cmd.marketplaceByService(serviceName)
} else {
cmd.marketplace()
}
}
示例12: Execute
func (cmd *CreateRoute) Execute(c flags.FlagContext) {
hostName := c.String("n")
space := cmd.spaceReq.GetSpace()
domain := cmd.domainReq.GetDomain()
_, apiErr := cmd.CreateRoute(hostName, domain, space.SpaceFields)
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
return
}
}
示例13: Requirements
func (cmd *CreateSpace) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) (reqs []requirements.Requirement, err error) {
if len(fc.Args()) != 1 {
cmd.ui.Failed(T("Incorrect Usage. Requires an argument\n\n") + command_registry.Commands.CommandUsage("create-space"))
}
reqs = []requirements.Requirement{requirementsFactory.NewLoginRequirement()}
if fc.String("o") == "" {
reqs = append(reqs, requirementsFactory.NewTargetedOrgRequirement())
}
return
}
示例14: Execute
func (cmd *CreateService) Execute(c flags.FlagContext) {
serviceName := c.Args()[0]
planName := c.Args()[1]
serviceInstanceName := c.Args()[2]
params := c.String("c")
tags := c.String("t")
tagsList := ui_helpers.ParseTags(tags)
paramsMap, err := json.ParseJsonFromFileOrString(params)
if err != nil {
cmd.ui.Failed(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 {
cmd.ui.Failed(err.Error())
}
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:
cmd.ui.Failed(err.Error())
}
}
示例15: 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
}