本文整理汇总了Golang中github.com/simonleung8/flags.FlagContext.Args方法的典型用法代码示例。如果您正苦于以下问题:Golang FlagContext.Args方法的具体用法?Golang FlagContext.Args怎么用?Golang FlagContext.Args使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/simonleung8/flags.FlagContext
的用法示例。
在下文中一共展示了FlagContext.Args方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Execute
func (cmd *CreateUser) Execute(c flags.FlagContext) {
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:
cmd.ui.Failed(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()}))
}
示例2: Execute
func (cmd *SetOrgRole) Execute(c flags.FlagContext) {
user := cmd.userReq.GetUser()
org := cmd.orgReq.GetOrganization()
role := models.UserInputToOrgRole[c.Args()[2]]
setRolesByUsername, err := cmd.flagRepo.FindByName("set_roles_by_username")
if err != nil {
cmd.ui.Failed(err.Error())
}
cmd.ui.Say(T("Assigning role {{.Role}} to user {{.TargetUser}} in org {{.TargetOrg}} as {{.CurrentUser}}...",
map[string]interface{}{
"Role": terminal.EntityNameColor(role),
"TargetUser": terminal.EntityNameColor(user.Username),
"TargetOrg": terminal.EntityNameColor(org.Name),
"CurrentUser": terminal.EntityNameColor(cmd.config.Username()),
}))
var apiErr error
if cmd.config.IsMinApiVersion("2.37.0") && setRolesByUsername.Enabled {
apiErr = cmd.userRepo.SetOrgRoleByUsername(user.Username, org.Guid, role)
} else {
apiErr = cmd.userRepo.SetOrgRole(user.Guid, org.Guid, role)
}
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
}
cmd.ui.Ok()
}
示例3: Execute
func (cmd *UnsetSpaceRole) Execute(c flags.FlagContext) {
spaceName := c.Args()[2]
role := models.UserInputToSpaceRole[c.Args()[3]]
user := cmd.userReq.GetUser()
org := cmd.orgReq.GetOrganization()
space, err := cmd.spaceRepo.FindByNameInOrg(spaceName, org.Guid)
if err != nil {
cmd.ui.Failed(err.Error())
}
cmd.ui.Say(T("Removing role {{.Role}} from user {{.TargetUser}} in org {{.TargetOrg}} / space {{.TargetSpace}} as {{.CurrentUser}}...",
map[string]interface{}{
"Role": terminal.EntityNameColor(role),
"TargetUser": terminal.EntityNameColor(user.Username),
"TargetOrg": terminal.EntityNameColor(org.Name),
"TargetSpace": terminal.EntityNameColor(space.Name),
"CurrentUser": terminal.EntityNameColor(cmd.config.Username()),
}))
if len(user.Guid) > 0 {
err = cmd.userRepo.UnsetSpaceRoleByGuid(user.Guid, space.Guid, role)
} else {
err = cmd.userRepo.UnsetSpaceRoleByUsername(user.Username, space.Guid, role)
}
if err != nil {
cmd.ui.Failed(err.Error())
}
cmd.ui.Ok()
}
示例4: Execute
func (cmd *PurgeServiceOffering) Execute(c flags.FlagContext) {
serviceName := c.Args()[0]
offering, apiErr := cmd.serviceRepo.FindServiceOfferingByLabelAndProvider(serviceName, c.String("p"))
switch apiErr.(type) {
case nil:
case *errors.ModelNotFoundError:
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
default:
cmd.ui.Failed(apiErr.Error())
}
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
}
cmd.ui.Say(T("Purging service {{.ServiceName}}...", map[string]interface{}{"ServiceName": serviceName}))
err := cmd.serviceRepo.PurgeServiceOffering(offering)
if err != nil {
cmd.ui.Failed(err.Error())
}
cmd.ui.Ok()
}
示例5: Execute
func (cmd *unbindFromStagingGroup) Execute(context flags.FlagContext) {
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
default:
cmd.ui.Failed(err.Error())
}
err = cmd.stagingGroupRepo.UnbindFromStagingSet(securityGroup.Guid)
if err != nil {
cmd.ui.Failed(err.Error())
}
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."))
}
示例6: 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("")
}
示例7: 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")}))
}
示例8: Execute
func (cmd *SetSpaceQuota) Execute(c flags.FlagContext) {
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 {
cmd.ui.Failed(err.Error())
}
if space.SpaceQuotaGuid != "" {
cmd.ui.Failed(T("This space already has an assigned space quota."))
}
quota, err := cmd.quotaRepo.FindByName(quotaName)
if err != nil {
cmd.ui.Failed(err.Error())
}
err = cmd.quotaRepo.AssociateSpaceWithQuota(space.Guid, quota.Guid)
if err != nil {
cmd.ui.Failed(err.Error())
}
cmd.ui.Ok()
}
示例9: Execute
func (cmd *RenameService) Execute(c flags.FlagContext) {
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.SERVICE_INSTANCE_NAME_TAKEN {
cmd.ui.Failed(T("{{.ErrorDescription}}\nTIP: Use '{{.CFServicesCommand}}' to view all services in this org and space.",
map[string]interface{}{
"ErrorDescription": httpError.Error(),
"CFServicesCommand": cf.Name() + " " + "services",
}))
} else {
cmd.ui.Failed(err.Error())
}
}
cmd.ui.Ok()
}
示例10: 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()
}
示例11: Execute
func (cmd *DeleteSpace) Execute(c flags.FlagContext) {
spaceName := c.Args()[0]
if !c.Bool("f") {
if !cmd.ui.ConfirmDelete(T("space"), spaceName) {
return
}
}
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()
apiErr := cmd.spaceRepo.Delete(space.Guid)
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
return
}
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
}
示例12: Execute
func (cmd *UnsetSpaceQuota) Execute(c flags.FlagContext) {
spaceName := c.Args()[0]
quotaName := c.Args()[1]
space, apiErr := cmd.spaceRepo.FindByName(spaceName)
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
return
}
quota, apiErr := cmd.quotaRepo.FindByName(quotaName)
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
return
}
cmd.ui.Say(T("Unassigning space quota {{.QuotaName}} from space {{.SpaceName}} as {{.Username}}...",
map[string]interface{}{
"QuotaName": terminal.EntityNameColor(quota.Name),
"SpaceName": terminal.EntityNameColor(space.Name),
"Username": terminal.EntityNameColor(cmd.config.Username())}))
apiErr = cmd.quotaRepo.UnassignQuotaFromSpace(space.Guid, quota.Guid)
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
return
}
cmd.ui.Ok()
}
示例13: 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()
}
示例14: Requirements
func (cmd *EnableServiceAccess) 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("enable-service-access"))
}
return []requirements.Requirement{requirementsFactory.NewLoginRequirement()}, nil
}
示例15: Execute
func (cmd *SetOrgRole) Execute(c flags.FlagContext) {
user := cmd.userReq.GetUser()
org := cmd.orgReq.GetOrganization()
role := models.UserInputToOrgRole[c.Args()[2]]
cmd.ui.Say(T("Assigning role {{.Role}} to user {{.TargetUser}} in org {{.TargetOrg}} as {{.CurrentUser}}...",
map[string]interface{}{
"Role": terminal.EntityNameColor(role),
"TargetUser": terminal.EntityNameColor(user.Username),
"TargetOrg": terminal.EntityNameColor(org.Name),
"CurrentUser": terminal.EntityNameColor(cmd.config.Username()),
}))
var err error
if len(user.Guid) > 0 {
err = cmd.userRepo.SetOrgRoleByGuid(user.Guid, org.Guid, role)
} else {
err = cmd.userRepo.SetOrgRoleByUsername(user.Username, org.Guid, role)
}
if err != nil {
cmd.ui.Failed(err.Error())
}
cmd.ui.Ok()
}