本文整理匯總了Golang中github.com/cloudfoundry/cli/cf/flags.FlagContext.Args方法的典型用法代碼示例。如果您正苦於以下問題:Golang FlagContext.Args方法的具體用法?Golang FlagContext.Args怎麽用?Golang FlagContext.Args使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry/cli/cf/flags.FlagContext
的用法示例。
在下文中一共展示了FlagContext.Args方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例2: 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
}
示例3: createBuildpack
func (cmd CreateBuildpack) createBuildpack(buildpackName string, c flags.FlagContext) (buildpack models.Buildpack, apiErr error) {
position, err := strconv.Atoi(c.Args()[2])
if err != nil {
apiErr = fmt.Errorf(T("Error {{.ErrorDescription}} is being passed in as the argument for 'Position' but 'Position' requires an integer. For more syntax help, see `cf create-buildpack -h`.", map[string]interface{}{"ErrorDescription": c.Args()[2]}))
return
}
enabled := c.Bool("enable")
disabled := c.Bool("disable")
if enabled && disabled {
apiErr = errors.New(T("Cannot specify both {{.Enabled}} and {{.Disabled}}.", map[string]interface{}{
"Enabled": "enabled",
"Disabled": "disabled",
}))
return
}
var enableOption *bool
if enabled {
enableOption = &enabled
}
if disabled {
disabled = false
enableOption = &disabled
}
buildpack, apiErr = cmd.buildpackRepo.Create(buildpackName, &position, enableOption, nil)
return
}
示例4: 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
}
示例5: Execute
func (cmd *DeleteServiceAuthTokenFields) Execute(c flags.FlagContext) error {
tokenLabel := c.Args()[0]
tokenProvider := c.Args()[1]
if c.Bool("f") == false {
if !cmd.ui.ConfirmDelete(T("service auth token"), fmt.Sprintf("%s %s", tokenLabel, tokenProvider)) {
return nil
}
}
cmd.ui.Say(T("Deleting service auth token as {{.CurrentUser}}",
map[string]interface{}{
"CurrentUser": terminal.EntityNameColor(cmd.config.Username()),
}))
token, err := cmd.authTokenRepo.FindByLabelAndProvider(tokenLabel, tokenProvider)
switch err.(type) {
case nil:
case *errors.ModelNotFoundError:
cmd.ui.Ok()
cmd.ui.Warn(T("Service Auth Token {{.Label}} {{.Provider}} does not exist.", map[string]interface{}{"Label": tokenLabel, "Provider": tokenProvider}))
return nil
default:
return err
}
err = cmd.authTokenRepo.Delete(token)
if err != nil {
return err
}
cmd.ui.Ok()
return nil
}
示例6: 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
}
示例7: Execute
func (cmd *PurgeServiceInstance) Execute(c flags.FlagContext) error {
instanceName := c.Args()[0]
instance, err := cmd.serviceRepo.FindInstanceByName(instanceName)
if err != nil {
if _, ok := err.(*errors.ModelNotFoundError); ok {
cmd.ui.Warn(T("Service instance {{.InstanceName}} not found", map[string]interface{}{"InstanceName": instanceName}))
return nil
}
return err
}
force := c.Bool("f")
if !force {
cmd.ui.Warn(cmd.scaryWarningMessage())
confirmed := cmd.ui.Confirm(T("Really purge service instance {{.InstanceName}} from Cloud Foundry?",
map[string]interface{}{"InstanceName": instanceName},
))
if !confirmed {
return nil
}
}
cmd.ui.Say(T("Purging service {{.InstanceName}}...", map[string]interface{}{"InstanceName": instanceName}))
err = cmd.serviceRepo.PurgeServiceInstance(instance)
if err != nil {
return err
}
cmd.ui.Ok()
return nil
}
示例8: 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
}
示例9: Execute
func (cmd *DeleteSpaceQuota) Execute(c flags.FlagContext) error {
quotaName := c.Args()[0]
if !c.Bool("f") {
response := cmd.ui.ConfirmDelete("quota", quotaName)
if !response {
return nil
}
}
cmd.ui.Say(T("Deleting space quota {{.QuotaName}} as {{.Username}}...", map[string]interface{}{
"QuotaName": terminal.EntityNameColor(quotaName),
"Username": terminal.EntityNameColor(cmd.config.Username()),
}))
quota, err := cmd.spaceQuotaRepo.FindByName(quotaName)
switch (err).(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 nil
default:
return err
}
err = cmd.spaceQuotaRepo.Delete(quota.GUID)
if err != nil {
return err
}
cmd.ui.Ok()
return nil
}
示例10: Execute
func (cmd *UnsetOrgRole) 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("Removing role {{.Role}} from user {{.TargetUser}} in org {{.TargetOrg}} as {{.CurrentUser}}...",
map[string]interface{}{
"Role": terminal.EntityNameColor(roleStr),
"TargetUser": terminal.EntityNameColor(c.Args()[0]),
"TargetOrg": terminal.EntityNameColor(c.Args()[1]),
"CurrentUser": terminal.EntityNameColor(cmd.config.Username()),
}))
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 {
return err
}
cmd.ui.Ok()
return nil
}
示例11: 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
}
示例12: NewSSHOptions
func NewSSHOptions(fc flags.FlagContext) (*SSHOptions, error) {
sshOptions := &SSHOptions{}
sshOptions.AppName = fc.Args()[0]
sshOptions.Index = uint(fc.Int("i"))
sshOptions.SkipHostValidation = fc.Bool("k")
sshOptions.SkipRemoteExecution = fc.Bool("N")
sshOptions.Command = fc.StringSlice("c")
if fc.IsSet("L") {
for _, arg := range fc.StringSlice("L") {
forwardSpec, err := sshOptions.parseLocalForwardingSpec(arg)
if err != nil {
return sshOptions, err
}
sshOptions.ForwardSpecs = append(sshOptions.ForwardSpecs, *forwardSpec)
}
}
if fc.IsSet("t") && fc.Bool("t") {
sshOptions.TerminalRequest = RequestTTYYes
}
if fc.IsSet("tt") && fc.Bool("tt") {
sshOptions.TerminalRequest = RequestTTYForce
}
if fc.Bool("T") {
sshOptions.TerminalRequest = RequestTTYNo
}
return sshOptions, nil
}
示例13: Execute
func (cmd *Restage) Execute(c flags.FlagContext) error {
app, err := cmd.appRepo.Read(c.Args()[0])
if notFound, ok := err.(*errors.ModelNotFoundError); ok {
return notFound
}
cmd.ui.Say(T("Restaging app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.CurrentUser}}...",
map[string]interface{}{
"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()),
}))
app.PackageState = ""
_, err = cmd.appStagingWatcher.WatchStaging(app, cmd.config.OrganizationFields().Name, cmd.config.SpaceFields().Name, func(app models.Application) (models.Application, error) {
return app, cmd.appRepo.CreateRestageRequest(app.GUID)
})
if err != nil {
cmd.ui.Say(T("Failed to watch staging of app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.CurrentUser}}...",
map[string]interface{}{
"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()),
}))
}
return nil
}
示例14: 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
}
示例15: 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
}