本文整理汇总了Golang中github.com/cloudfoundry/cli/flags.FlagContext类的典型用法代码示例。如果您正苦于以下问题:Golang FlagContext类的具体用法?Golang FlagContext怎么用?Golang FlagContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FlagContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Execute
func (cmd *RenameService) Execute(c flags.FlagContext) error {
newName := c.Args()[1]
serviceInstance := cmd.serviceInstanceReq.GetServiceInstance()
cmd.ui.Say(T("Renaming service {{.ServiceName}} to {{.NewServiceName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.CurrentUser}}...",
map[string]interface{}{
"ServiceName": terminal.EntityNameColor(serviceInstance.Name),
"NewServiceName": terminal.EntityNameColor(newName),
"OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
"SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name),
"CurrentUser": terminal.EntityNameColor(cmd.config.Username()),
}))
err := cmd.serviceRepo.RenameService(serviceInstance, newName)
if err != nil {
if httpError, ok := err.(errors.HTTPError); ok && httpError.ErrorCode() == errors.ServiceInstanceNameTaken {
return errors.New(T("{{.ErrorDescription}}\nTIP: Use '{{.CFServicesCommand}}' to view all services in this org and space.",
map[string]interface{}{
"ErrorDescription": httpError.Error(),
"CFServicesCommand": cf.Name + " " + "services",
}))
}
return err
}
cmd.ui.Ok()
return nil
}
开发者ID:Reejoshi,项目名称:cli,代码行数:28,代码来源:rename_service.go
示例2: Requirements
func (cmd *AddPluginRepo) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) (reqs []requirements.Requirement, err error) {
if len(fc.Args()) != 2 {
cmd.ui.Failed(T("Incorrect Usage. Requires [REPO_NAME] [URL] as arguments\n\n") + command_registry.Commands.CommandUsage("add-plugin-repo"))
}
return
}
开发者ID:lamproae,项目名称:cli,代码行数:7,代码来源:add_plugin_repo.go
示例3: Execute
func (cmd *Env) Execute(c flags.FlagContext) {
app, err := cmd.appRepo.Read(c.Args()[0])
if notFound, ok := err.(*errors.ModelNotFoundError); ok {
cmd.ui.Failed(notFound.Error())
}
cmd.ui.Say(T("Getting env variables for app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...",
map[string]interface{}{
"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())}))
env, err := cmd.appRepo.ReadEnv(app.GUID)
if err != nil {
cmd.ui.Failed(err.Error())
}
cmd.ui.Ok()
cmd.ui.Say("")
cmd.displaySystemiAndAppProvidedEnvironment(env.System, env.Application)
cmd.ui.Say("")
cmd.displayUserProvidedEnvironment(env.Environment)
cmd.ui.Say("")
cmd.displayRunningEnvironment(env.Running)
cmd.ui.Say("")
cmd.displayStagingEnvironment(env.Staging)
cmd.ui.Say("")
}
开发者ID:yingkitw,项目名称:cli,代码行数:30,代码来源:env.go
示例4: Execute
func (cmd *DeleteServiceBroker) Execute(c flags.FlagContext) {
brokerName := c.Args()[0]
if !c.Bool("f") && !cmd.ui.ConfirmDelete(T("service-broker"), brokerName) {
return
}
cmd.ui.Say(T("Deleting service broker {{.Name}} as {{.Username}}...",
map[string]interface{}{
"Name": terminal.EntityNameColor(brokerName),
"Username": terminal.EntityNameColor(cmd.config.Username()),
}))
broker, apiErr := cmd.repo.FindByName(brokerName)
switch apiErr.(type) {
case nil:
case *errors.ModelNotFoundError:
cmd.ui.Ok()
cmd.ui.Warn(T("Service Broker {{.Name}} does not exist.", map[string]interface{}{"Name": brokerName}))
return
default:
cmd.ui.Failed(apiErr.Error())
return
}
apiErr = cmd.repo.Delete(broker.GUID)
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
return
}
cmd.ui.Ok()
return
}
开发者ID:yingkitw,项目名称:cli,代码行数:34,代码来源:delete_service_broker.go
示例5: Execute
func (cmd *PluginUninstall) Execute(c flags.FlagContext) error {
pluginName := c.Args()[0]
pluginNameMap := map[string]interface{}{"PluginName": pluginName}
cmd.ui.Say(fmt.Sprintf(T("Uninstalling plugin {{.PluginName}}...", pluginNameMap)))
plugins := cmd.config.Plugins()
if _, ok := plugins[pluginName]; !ok {
return errors.New(fmt.Sprintf(T("Plugin name {{.PluginName}} does not exist", pluginNameMap)))
}
pluginMetadata := plugins[pluginName]
warn, err := cmd.notifyPluginUninstalling(pluginMetadata)
if err != nil {
return err
}
if warn != nil {
cmd.ui.Say("Error invoking plugin: " + warn.Error() + ". Process to uninstall ...")
}
time.Sleep(500 * time.Millisecond) //prevent 'process being used' error in Windows
err = os.Remove(pluginMetadata.Location)
if err != nil {
cmd.ui.Warn("Error removing plugin binary: " + err.Error())
}
cmd.config.RemovePlugin(pluginName)
cmd.ui.Ok()
cmd.ui.Say(fmt.Sprintf(T("Plugin {{.PluginName}} successfully uninstalled.", pluginNameMap)))
return nil
}
开发者ID:jsloyer,项目名称:cli,代码行数:35,代码来源:uninstall_plugin.go
示例6: Execute
func (cmd *DeleteOrphanedRoutes) Execute(c flags.FlagContext) {
force := c.Bool("f")
if !force {
response := cmd.ui.Confirm(T("Really delete orphaned routes?{{.Prompt}}",
map[string]interface{}{"Prompt": terminal.PromptColor(">")}))
if !response {
return
}
}
cmd.ui.Say(T("Getting routes as {{.Username}} ...\n",
map[string]interface{}{"Username": terminal.EntityNameColor(cmd.config.Username())}))
apiErr := cmd.routeRepo.ListRoutes(func(route models.Route) bool {
if len(route.Apps) == 0 {
cmd.ui.Say(T("Deleting route {{.Route}}...",
map[string]interface{}{"Route": terminal.EntityNameColor(route.Host + "." + route.Domain.Name)}))
apiErr := cmd.routeRepo.Delete(route.Guid)
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
return false
}
}
return true
})
if apiErr != nil {
cmd.ui.Failed(T("Failed fetching routes.\n{{.Err}}", map[string]interface{}{"Err": apiErr.Error()}))
return
}
cmd.ui.Ok()
}
开发者ID:vframbach,项目名称:cli,代码行数:34,代码来源:delete_orphaned_routes.go
示例7: Execute
func (cmd *unbindFromStagingGroup) Execute(context flags.FlagContext) error {
name := context.Args()[0]
cmd.ui.Say(T("Unbinding security group {{.security_group}} from defaults for staging as {{.username}}",
map[string]interface{}{
"security_group": terminal.EntityNameColor(name),
"username": terminal.EntityNameColor(cmd.configRepo.Username()),
}))
securityGroup, err := cmd.securityGroupRepo.Read(name)
switch (err).(type) {
case nil:
case *errors.ModelNotFoundError:
cmd.ui.Ok()
cmd.ui.Warn(T("Security group {{.security_group}} {{.error_message}}",
map[string]interface{}{
"security_group": terminal.EntityNameColor(name),
"error_message": terminal.WarningColor(T("does not exist.")),
}))
return nil
default:
return err
}
err = cmd.stagingGroupRepo.UnbindFromStagingSet(securityGroup.GUID)
if err != nil {
return err
}
cmd.ui.Ok()
cmd.ui.Say("\n\n")
cmd.ui.Say(T("TIP: Changes will not apply to existing running applications until they are restarted."))
return nil
}
开发者ID:Reejoshi,项目名称:cli,代码行数:34,代码来源:unbind_staging_security_group.go
示例8: Execute
func (cmd *SetOrgRole) Execute(c flags.FlagContext) error {
user := cmd.userReq.GetUser()
org := cmd.orgReq.GetOrganization()
roleStr := c.Args()[2]
role, err := models.RoleFromString(roleStr)
if err != nil {
return err
}
cmd.ui.Say(T("Assigning role {{.Role}} to user {{.TargetUser}} in org {{.TargetOrg}} as {{.CurrentUser}}...",
map[string]interface{}{
"Role": terminal.EntityNameColor(roleStr),
"TargetUser": terminal.EntityNameColor(user.Username),
"TargetOrg": terminal.EntityNameColor(org.Name),
"CurrentUser": terminal.EntityNameColor(cmd.config.Username()),
}))
err = cmd.SetOrgRole(org.GUID, role, user.GUID, user.Username)
if err != nil {
return err
}
cmd.ui.Ok()
return nil
}
开发者ID:Reejoshi,项目名称:cli,代码行数:25,代码来源:set_org_role.go
示例9: 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
}
开发者ID:Reejoshi,项目名称:cli,代码行数:34,代码来源:login.go
示例10: Execute
func (cmd *UnsetEnv) Execute(c flags.FlagContext) {
varName := c.Args()[1]
app := cmd.appReq.GetApplication()
cmd.ui.Say(T("Removing env variable {{.VarName}} from app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.CurrentUser}}...",
map[string]interface{}{
"VarName": terminal.EntityNameColor(varName),
"AppName": terminal.EntityNameColor(app.Name),
"OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
"SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name),
"CurrentUser": terminal.EntityNameColor(cmd.config.Username())}))
envParams := app.EnvironmentVars
if _, ok := envParams[varName]; !ok {
cmd.ui.Ok()
cmd.ui.Warn(T("Env variable {{.VarName}} was not set.", map[string]interface{}{"VarName": varName}))
return
}
delete(envParams, varName)
_, 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(T("TIP: Use '{{.Command}}' to ensure your env variable changes take effect",
map[string]interface{}{"Command": terminal.CommandColor(cf.Name() + " restage")}))
}
开发者ID:vframbach,项目名称:cli,代码行数:32,代码来源:unset_env.go
示例11: Requirements
func (cmd *PluginUninstall) 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("uninstall-plugin"))
}
return
}
开发者ID:vframbach,项目名称:cli,代码行数:7,代码来源:uninstall_plugin.go
示例12: Execute
func (cmd *DeleteSpaceQuota) Execute(c flags.FlagContext) {
quotaName := c.Args()[0]
if !c.Bool("f") {
response := cmd.ui.ConfirmDelete("quota", quotaName)
if !response {
return
}
}
cmd.ui.Say(T("Deleting space quota {{.QuotaName}} as {{.Username}}...", map[string]interface{}{
"QuotaName": terminal.EntityNameColor(quotaName),
"Username": terminal.EntityNameColor(cmd.config.Username()),
}))
quota, apiErr := cmd.spaceQuotaRepo.FindByName(quotaName)
switch (apiErr).(type) {
case nil: // no error
case *errors.ModelNotFoundError:
cmd.ui.Ok()
cmd.ui.Warn(T("Quota {{.QuotaName}} does not exist", map[string]interface{}{"QuotaName": quotaName}))
return
default:
cmd.ui.Failed(apiErr.Error())
}
apiErr = cmd.spaceQuotaRepo.Delete(quota.Guid)
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
}
cmd.ui.Ok()
}
开发者ID:rakutentech,项目名称:cli,代码行数:33,代码来源:delete_quota.go
示例13: Execute
func (cmd *DeleteSecurityGroup) Execute(context flags.FlagContext) {
name := context.Args()[0]
cmd.ui.Say(T("Deleting security group {{.security_group}} as {{.username}}",
map[string]interface{}{
"security_group": terminal.EntityNameColor(name),
"username": terminal.EntityNameColor(cmd.configRepo.Username()),
}))
if !context.Bool("f") {
response := cmd.ui.ConfirmDelete(T("security group"), name)
if !response {
return
}
}
group, err := cmd.securityGroupRepo.Read(name)
switch err.(type) {
case nil:
case *errors.ModelNotFoundError:
cmd.ui.Ok()
cmd.ui.Warn(T("Security group {{.security_group}} does not exist", map[string]interface{}{"security_group": name}))
return
default:
cmd.ui.Failed(err.Error())
}
err = cmd.securityGroupRepo.Delete(group.Guid)
if err != nil {
cmd.ui.Failed(err.Error())
}
cmd.ui.Ok()
}
开发者ID:cloudfoundry-incubator,项目名称:Diego-Enabler,代码行数:33,代码来源:delete_security_group.go
示例14: Requirements
func (cmd *ShowSecurityGroup) 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("security-group"))
}
return []requirements.Requirement{requirementsFactory.NewLoginRequirement()}, nil
}
开发者ID:vframbach,项目名称:cli,代码行数:7,代码来源:security_group.go
示例15: 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)
}
开发者ID:vframbach,项目名称:cli,代码行数:26,代码来源:repo_plugins.go
示例16: Execute
func (cmd *ListStack) Execute(c flags.FlagContext) {
stackName := c.Args()[0]
stack, apiErr := cmd.stacksRepo.FindByName(stackName)
if c.Bool("guid") {
cmd.ui.Say(stack.GUID)
} else {
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
return
}
cmd.ui.Say(T("Getting stack '{{.Stack}}' in org {{.OrganizationName}} / space {{.SpaceName}} as {{.Username}}...",
map[string]interface{}{"Stack": stackName,
"OrganizationName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
"SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name),
"Username": terminal.EntityNameColor(cmd.config.Username())}))
cmd.ui.Ok()
cmd.ui.Say("")
table := cmd.ui.Table([]string{T("name"), T("description")})
table.Add(stack.Name, stack.Description)
table.Print()
}
}
开发者ID:yingkitw,项目名称:cli,代码行数:26,代码来源:stack.go
示例17: Requirements
func (cmd *Plugins) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) (reqs []requirements.Requirement, err error) {
if len(fc.Args()) != 0 {
cmd.ui.Failed(T("Incorrect Usage. No argument required\n\n") + command_registry.Commands.CommandUsage("plugins"))
}
return
}
开发者ID:vframbach,项目名称:cli,代码行数:7,代码来源:plugins.go
示例18: Execute
func (cmd *UnsetOrgRole) Execute(c flags.FlagContext) {
user := cmd.userReq.GetUser()
org := cmd.orgReq.GetOrganization()
role := models.UserInputToOrgRole[c.Args()[2]]
cmd.ui.Say(T("Removing role {{.Role}} from user {{.TargetUser}} in org {{.TargetOrg}} as {{.CurrentUser}}...",
map[string]interface{}{
"Role": terminal.EntityNameColor(role),
"TargetUser": terminal.EntityNameColor(c.Args()[0]),
"TargetOrg": terminal.EntityNameColor(c.Args()[1]),
"CurrentUser": terminal.EntityNameColor(cmd.config.Username()),
}))
var err error
if len(user.Guid) > 0 {
err = cmd.userRepo.UnsetOrgRoleByGuid(user.Guid, org.Guid, role)
} else {
err = cmd.userRepo.UnsetOrgRoleByUsername(user.Username, org.Guid, role)
}
if err != nil {
cmd.ui.Failed(err.Error())
}
cmd.ui.Ok()
}
开发者ID:vframbach,项目名称:cli,代码行数:26,代码来源:unset_org_role.go
示例19: Execute
func (cmd *DeleteUser) Execute(c flags.FlagContext) {
username := c.Args()[0]
force := c.Bool("f")
if !force && !cmd.ui.ConfirmDelete(T("user"), username) {
return
}
cmd.ui.Say(T("Deleting user {{.TargetUser}} as {{.CurrentUser}}...",
map[string]interface{}{
"TargetUser": terminal.EntityNameColor(username),
"CurrentUser": terminal.EntityNameColor(cmd.config.Username()),
}))
user, apiErr := cmd.userRepo.FindByUsername(username)
switch apiErr.(type) {
case nil:
case *errors.ModelNotFoundError:
cmd.ui.Ok()
cmd.ui.Warn(T("User {{.TargetUser}} does not exist.", map[string]interface{}{"TargetUser": username}))
return
default:
cmd.ui.Failed(apiErr.Error())
return
}
apiErr = cmd.userRepo.Delete(user.Guid)
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
return
}
cmd.ui.Ok()
}
开发者ID:cloudfoundry-incubator,项目名称:Diego-Enabler,代码行数:34,代码来源:delete_user.go
示例20: Execute
func (cmd *SetEnv) Execute(c flags.FlagContext) {
varName := c.Args()[1]
varValue := c.Args()[2]
app := cmd.appReq.GetApplication()
cmd.ui.Say(T("Setting env variable '{{.VarName}}' to '{{.VarValue}}' for app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.CurrentUser}}...",
map[string]interface{}{
"VarName": terminal.EntityNameColor(varName),
"VarValue": terminal.EntityNameColor(varValue),
"AppName": terminal.EntityNameColor(app.Name),
"OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
"SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name),
"CurrentUser": terminal.EntityNameColor(cmd.config.Username())}))
if len(app.EnvironmentVars) == 0 {
app.EnvironmentVars = map[string]interface{}{}
}
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(T("TIP: Use '{{.Command}}' to ensure your env variable changes take effect",
map[string]interface{}{"Command": terminal.CommandColor(cf.Name + " restage")}))
}
开发者ID:cloudfoundry-incubator,项目名称:Diego-Enabler,代码行数:31,代码来源:set_env.go
注:本文中的github.com/cloudfoundry/cli/flags.FlagContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论