本文整理匯總了Golang中code/cloudfoundry/org/cli/cf/flags.FlagContext類的典型用法代碼示例。如果您正苦於以下問題:Golang FlagContext類的具體用法?Golang FlagContext怎麽用?Golang FlagContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了FlagContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: printer
func (cmd *OrgUsers) printer(c flags.FlagContext) userprint.UserPrinter {
var roles []models.Role
if c.Bool("a") {
roles = []models.Role{models.RoleOrgUser}
} else {
roles = []models.Role{models.RoleOrgManager, models.RoleBillingManager, models.RoleOrgAuditor}
}
if cmd.pluginCall {
return userprint.NewOrgUsersPluginPrinter(
cmd.pluginModel,
cmd.userLister(),
roles,
)
}
return &userprint.OrgUsersUIPrinter{
UI: cmd.ui,
UserLister: cmd.userLister(),
Roles: roles,
RoleDisplayNames: map[models.Role]string{
models.RoleOrgUser: T("USERS"),
models.RoleOrgManager: T("ORG MANAGER"),
models.RoleBillingManager: T("BILLING MANAGER"),
models.RoleOrgAuditor: T("ORG AUDITOR"),
},
}
}
示例2: Execute
func (cmd *DeleteOrphanedRoutes) Execute(c flags.FlagContext) error {
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 nil
}
}
cmd.ui.Say(T("Getting routes as {{.Username}} ...\n",
map[string]interface{}{"Username": terminal.EntityNameColor(cmd.config.Username())}))
err := 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.URL())}))
apiErr := cmd.routeRepo.Delete(route.GUID)
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
return false
}
}
return true
})
if err != nil {
return errors.New(T("Failed fetching routes.\n{{.Err}}", map[string]interface{}{"Err": err.Error()}))
}
cmd.ui.Ok()
return nil
}
示例3: Execute
func (cmd *DeleteSecurityGroup) Execute(context flags.FlagContext) error {
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 nil
}
}
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 nil
default:
return err
}
err = cmd.securityGroupRepo.Delete(group.GUID)
if err != nil {
return err
}
cmd.ui.Ok()
return nil
}
示例4: Execute
func (cmd *PluginUninstall) Execute(c flags.FlagContext) error {
pluginName := c.Args()[0]
pluginNameMap := map[string]interface{}{"PluginName": pluginName}
cmd.ui.Say(T("Uninstalling plugin {{.PluginName}}...", pluginNameMap))
plugins := cmd.config.Plugins()
if _, ok := plugins[pluginName]; !ok {
return errors.New(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(T("Plugin {{.PluginName}} successfully uninstalled.", pluginNameMap))
return nil
}
示例5: Execute
func (cmd *SetHealthCheck) Execute(fc flags.FlagContext) error {
healthCheckType := fc.Args()[1]
app := cmd.appReq.GetApplication()
if app.HealthCheckType == healthCheckType {
cmd.ui.Say(fmt.Sprintf("%s "+T("health_check_type is already set")+" to '%s'", app.Name, app.HealthCheckType))
return nil
}
cmd.ui.Say(fmt.Sprintf(T(""), app.Name, healthCheckType))
cmd.ui.Say(T("Updating {{.AppName}} health_check_type to '{{.HealthCheckType}}'",
map[string]interface{}{
"AppName": app.Name,
"HealthCheckType": healthCheckType,
},
))
cmd.ui.Say("")
updatedApp, err := cmd.appRepo.Update(app.GUID, models.AppParams{HealthCheckType: &healthCheckType})
if err != nil {
return errors.New(T("Error updating health_check_type for ") + app.Name + ": " + err.Error())
}
if updatedApp.HealthCheckType == healthCheckType {
cmd.ui.Ok()
} else {
return errors.New(T("health_check_type is not set to ") + healthCheckType + T(" for ") + app.Name)
}
return nil
}
示例6: 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
}
示例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 *DeleteUser) Execute(c flags.FlagContext) error {
username := c.Args()[0]
force := c.Bool("f")
if !force && !cmd.ui.ConfirmDelete(T("user"), username) {
return nil
}
cmd.ui.Say(T("Deleting user {{.TargetUser}} as {{.CurrentUser}}...",
map[string]interface{}{
"TargetUser": terminal.EntityNameColor(username),
"CurrentUser": terminal.EntityNameColor(cmd.config.Username()),
}))
user, err := cmd.userRepo.FindByUsername(username)
switch err.(type) {
case nil:
case *errors.ModelNotFoundError:
cmd.ui.Ok()
cmd.ui.Warn(T("User {{.TargetUser}} does not exist.", map[string]interface{}{"TargetUser": username}))
return nil
default:
return err
}
err = cmd.userRepo.Delete(user.GUID)
if err != nil {
return err
}
cmd.ui.Ok()
return nil
}
示例9: Execute
func (cmd *DeleteServiceBroker) Execute(c flags.FlagContext) error {
brokerName := c.Args()[0]
if !c.Bool("f") && !cmd.ui.ConfirmDelete(T("service-broker"), brokerName) {
return nil
}
cmd.ui.Say(T("Deleting service broker {{.Name}} as {{.Username}}...",
map[string]interface{}{
"Name": terminal.EntityNameColor(brokerName),
"Username": terminal.EntityNameColor(cmd.config.Username()),
}))
broker, err := cmd.repo.FindByName(brokerName)
switch err.(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 nil
default:
return err
}
err = cmd.repo.Delete(broker.GUID)
if err != nil {
return err
}
cmd.ui.Ok()
return nil
}
示例10: Execute
func (cmd *DeleteSpace) Execute(c flags.FlagContext) error {
spaceName := c.Args()[0]
if !c.Bool("f") {
if !cmd.ui.ConfirmDelete(T("space"), spaceName) {
return nil
}
}
cmd.ui.Say(T("Deleting space {{.TargetSpace}} in org {{.TargetOrg}} as {{.CurrentUser}}...",
map[string]interface{}{
"TargetSpace": terminal.EntityNameColor(spaceName),
"TargetOrg": terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
"CurrentUser": terminal.EntityNameColor(cmd.config.Username()),
}))
space := cmd.spaceReq.GetSpace()
err := cmd.spaceRepo.Delete(space.GUID)
if err != nil {
return err
}
cmd.ui.Ok()
if cmd.config.SpaceFields().GUID == space.GUID {
cmd.config.SetSpaceFields(models.SpaceFields{})
cmd.ui.Say(T("TIP: No space targeted, use '{{.CfTargetCommand}}' to target a space",
map[string]interface{}{"CfTargetCommand": cf.Name + " target -s"}))
}
return nil
}
示例11: Execute
func (cmd *RestartAppInstance) Execute(fc flags.FlagContext) error {
app := cmd.appReq.GetApplication()
instance, err := strconv.Atoi(fc.Args()[1])
if err != nil {
return errors.New(T("Instance must be a non-negative integer"))
}
cmd.ui.Say(T("Restarting instance {{.Instance}} of application {{.AppName}} as {{.Username}}",
map[string]interface{}{
"Instance": instance,
"AppName": terminal.EntityNameColor(app.Name),
"Username": terminal.EntityNameColor(cmd.config.Username()),
}))
err = cmd.appInstancesRepo.DeleteInstance(app.GUID, instance)
if err != nil {
return err
}
cmd.ui.Ok()
cmd.ui.Say("")
return nil
}
示例12: Execute
func (cmd *CreateUser) Execute(c flags.FlagContext) error {
username := c.Args()[0]
password := c.Args()[1]
cmd.ui.Say(T("Creating user {{.TargetUser}}...",
map[string]interface{}{
"TargetUser": terminal.EntityNameColor(username),
"CurrentUser": terminal.EntityNameColor(cmd.config.Username()),
}))
err := cmd.userRepo.Create(username, password)
switch err.(type) {
case nil:
case *errors.ModelAlreadyExistsError:
cmd.ui.Warn("%s", err.Error())
default:
return errors.New(T("Error creating user {{.TargetUser}}.\n{{.Error}}",
map[string]interface{}{
"TargetUser": terminal.EntityNameColor(username),
"Error": err.Error(),
}))
}
cmd.ui.Ok()
cmd.ui.Say(T("\nTIP: Assign roles with '{{.CurrentUser}} set-org-role' and '{{.CurrentUser}} set-space-role'", map[string]interface{}{"CurrentUser": cf.Name}))
return nil
}
示例13: Execute
func (cmd *ListStack) Execute(c flags.FlagContext) error {
stackName := c.Args()[0]
stack, err := cmd.stacksRepo.FindByName(stackName)
if c.Bool("guid") {
cmd.ui.Say(stack.GUID)
} else {
if err != nil {
return err
}
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)
err = table.Print()
if err != nil {
return err
}
}
return nil
}
示例14: Execute
func (cmd *SetSpaceQuota) Execute(c flags.FlagContext) error {
spaceName := c.Args()[0]
quotaName := c.Args()[1]
cmd.ui.Say(T("Assigning space quota {{.QuotaName}} to space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{
"QuotaName": terminal.EntityNameColor(quotaName),
"SpaceName": terminal.EntityNameColor(spaceName),
"Username": terminal.EntityNameColor(cmd.config.Username()),
}))
space, err := cmd.spaceRepo.FindByName(spaceName)
if err != nil {
return err
}
if space.SpaceQuotaGUID != "" {
return errors.New(T("This space already has an assigned space quota."))
}
quota, err := cmd.quotaRepo.FindByName(quotaName)
if err != nil {
return err
}
err = cmd.quotaRepo.AssociateSpaceWithQuota(space.GUID, quota.GUID)
if err != nil {
return err
}
cmd.ui.Ok()
return nil
}
示例15: 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
}