func (cmd *ApiCommand) Execute(args []string) error { if cmd.Config.Experimental() == false { oldCmd.Main(os.Getenv("CF_TRACE"), os.Args) return nil } cmd.UI.DisplayText("This command is in EXPERIMENTAL stage and may change without notice") cmd.UI.DisplayNewline() if cmd.Unset { return cmd.ClearTarget() } if cmd.OptionalArgs.URL != "" { err := cmd.SetAPI() if err != nil { return err } } if cmd.Config.Target() == "" { cmd.UI.DisplayText("No api endpoint set. Use '{{.Name}}' to set an endpoint", map[string]interface{}{ "Name": "cf api", }) return nil } return DisplayCurrentTargetInformation(cmd.Config, cmd.UI) }
func (cmd UnbindServiceCommand) Execute(args []string) error { if cmd.Config.Experimental() == false { oldCmd.Main(os.Getenv("CF_TRACE"), os.Args) return nil } cmd.UI.DisplayText("This command is in EXPERIMENTAL stage and may change without notice") cmd.UI.DisplayNewline() err := common.CheckTarget(cmd.Config, true, true) if err != nil { return err } space := cmd.Config.TargetedSpace() user, err := cmd.Config.CurrentUser() if err != nil { return err } cmd.UI.DisplayHeaderFlavorText("Unbinding app {{.AppName}} from service {{.ServiceName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.CurrentUser}}...", map[string]interface{}{ "AppName": cmd.RequiredArgs.AppName, "ServiceName": cmd.RequiredArgs.ServiceInstanceName, "OrgName": cmd.Config.TargetedOrganization().Name, "SpaceName": space.Name, "CurrentUser": user.Name, }) warnings, err := cmd.Actor.UnbindServiceBySpace(cmd.RequiredArgs.AppName, cmd.RequiredArgs.ServiceInstanceName, space.GUID) cmd.UI.DisplayWarnings(warnings) if err != nil { if _, ok := err.(v2actions.ServiceBindingNotFoundError); ok { cmd.UI.DisplayWarning("Binding between {{.InstanceName}} and {{.AppName}} did not exist", map[string]interface{}{ "AppName": cmd.RequiredArgs.AppName, "InstanceName": cmd.RequiredArgs.ServiceInstanceName, }) } else { return common.HandleError(err) } } cmd.UI.DisplayOK() return nil }
func (_ RestartAppInstanceCommand) Execute(args []string) error { cmd.Main(os.Getenv("CF_TRACE"), os.Args) return nil }
func (_ UnsharePrivateDomainCommand) Execute(args []string) error { cmd.Main(os.Getenv("CF_TRACE"), os.Args) return nil }
func (_ RunningEnvironmentVariableGroupCommand) Execute(args []string) error { cmd.Main(os.Getenv("CF_TRACE"), os.Args) return nil }
func (_ UnsetOrgRoleCommand) Execute(args []string) error { cmd.Main(os.Getenv("CF_TRACE"), os.Args) return nil }
func (_ SpaceSSHAllowedCommand) Execute(args []string) error { cmd.Main(os.Getenv("CF_TRACE"), os.Args) return nil }
func (_ DeleteSpaceQuotaCommand) Execute(args []string) error { cmd.Main(os.Getenv("CF_TRACE"), os.Args) return nil }
func (_ RemovePluginRepoCommand) Execute(args []string) error { cmd.Main(os.Getenv("CF_TRACE"), os.Args) return nil }
func (_ RouterGroupsCommand) Execute(args []string) error { cmd.Main(os.Getenv("CF_TRACE"), os.Args) return nil }
func (_ CreateAppManifestCommand) Execute(args []string) error { cmd.Main(os.Getenv("CF_TRACE"), os.Args) return nil }
func (_ DisableServiceAccessCommand) Execute(args []string) error { cmd.Main(os.Getenv("CF_TRACE"), os.Args) return nil }
func (_ InstallPluginCommand) Execute(args []string) error { cmd.Main(os.Getenv("CF_TRACE"), os.Args) return nil }
func parse(args []string) { parser := flags.NewParser(&v2.Commands, flags.HelpFlag) parser.CommandHandler = executionWrapper extraArgs, err := parser.ParseArgs(args) if err == nil { return } if flagErr, ok := err.(*flags.Error); ok { switch flagErr.Type { case flags.ErrHelp, flags.ErrUnknownFlag, flags.ErrExpectedArgument: _, found := reflect.TypeOf(v2.Commands).FieldByNameFunc( func(fieldName string) bool { field, _ := reflect.TypeOf(v2.Commands).FieldByName(fieldName) return parser.Active != nil && parser.Active.Name == field.Tag.Get("command") }, ) if found && flagErr.Type == flags.ErrUnknownFlag && parser.Active.Name == "set-env" { newArgs := []string{} for _, arg := range args { if arg[0] == '-' { newArgs = append(newArgs, fmt.Sprintf("%s%s", v2.WorkAroundPrefix, arg)) } else { newArgs = append(newArgs, arg) } } parse(newArgs) return } if flagErr.Type == flags.ErrUnknownFlag || flagErr.Type == flags.ErrExpectedArgument { fmt.Fprintf(os.Stderr, "Incorrect Usage: %s\n\n", flagErr.Error()) } if found { parse([]string{"help", parser.Active.Name}) } else { switch len(extraArgs) { case 0: parse([]string{"help"}) case 1: if !isOption(extraArgs[0]) || (len(args) > 1 && extraArgs[0] == "-a") { parse([]string{"help", extraArgs[0]}) } else { parse([]string{"help"}) } default: if isCommand(extraArgs[0]) { parse([]string{"help", extraArgs[0]}) } else { parse(extraArgs[1:]) } } } if flagErr.Type == flags.ErrUnknownFlag || flagErr.Type == flags.ErrExpectedArgument { os.Exit(1) } case flags.ErrRequired: fmt.Fprintf(os.Stderr, "Incorrect Usage: %s\n\n", flagErr.Error()) parse([]string{"help", args[0]}) os.Exit(1) case flags.ErrUnknownCommand: cmd.Main(os.Getenv("CF_TRACE"), os.Args) case flags.ErrCommandRequired: if v2.Commands.VerboseOrVersion { parse([]string{"version"}) } else { parse([]string{"help"}) } default: fmt.Fprintf(os.Stderr, "Unexpected flag error\ntype: %s\nmessage: %s\n", flagErr.Type, flagErr.Error()) } } else if err == ErrFailed { os.Exit(1) } else { fmt.Fprintf(os.Stderr, "Unexpected error: %s\n", err.Error()) os.Exit(1) } }
func (_ SetEnvCommand) Execute(args []string) error { //TODO: Be sure to sanitize the WorkAroundPrefix cmd.Main(os.Getenv("CF_TRACE"), os.Args) return nil }
func (_ CreateSharedDomainCommand) Execute(args []string) error { cmd.Main(os.Getenv("CF_TRACE"), os.Args) return nil }
func (_ EnableSSHCommand) Execute(args []string) error { cmd.Main(os.Getenv("CF_TRACE"), os.Args) return nil }
func (_ RenameServiceBrokerCommand) Execute(args []string) error { cmd.Main(os.Getenv("CF_TRACE"), os.Args) return nil }
func (_ CreateUserProvidedServiceCommand) Execute(args []string) error { cmd.Main(os.Getenv("CF_TRACE"), os.Args) return nil }
func (_ MigrateServiceInstancesCommand) Execute(args []string) error { cmd.Main(os.Getenv("CF_TRACE"), os.Args) return nil }
func (_ OauthTokenCommand) Execute(args []string) error { cmd.Main(os.Getenv("CF_TRACE"), os.Args) return nil }
func (cmd *DeleteOrphanedRoutesCommand) Execute(args []string) error { if cmd.Config.Experimental() == false { oldCmd.Main(os.Getenv("CF_TRACE"), os.Args) return nil } cmd.UI.DisplayText(ExperimentalWarning) cmd.UI.DisplayNewline() err := common.CheckTarget(cmd.Config, true, true) if err != nil { return err } if !cmd.Force { deleteOrphanedRoutes, promptErr := cmd.UI.DisplayBoolPrompt("Really delete orphaned routes?", false) if err != nil { return promptErr } if !deleteOrphanedRoutes { return nil } } user, err := cmd.Config.CurrentUser() if err != nil { return err } cmd.UI.DisplayHeaderFlavorText("Getting routes as {{.CurrentUser}} ...", map[string]interface{}{ "CurrentUser": user.Name, }) cmd.UI.DisplayNewline() routes, warnings, err := cmd.Actor.GetOrphanedRoutesBySpace(cmd.Config.TargetedSpace().GUID) cmd.UI.DisplayWarnings(warnings) if err != nil { switch err.(type) { case v2actions.OrphanedRoutesNotFoundError: // Do nothing to parity the existing behavior default: return common.HandleError(err) } } for _, route := range routes { cmd.UI.DisplayText("Deleting route {{.Route}} ...", map[string]interface{}{ "Route": route.String(), }) warnings, err = cmd.Actor.DeleteRoute(route.GUID) cmd.UI.DisplayWarnings(warnings) if err != nil { return common.HandleError(err) } } cmd.UI.DisplayOK() return nil }
func (_ UpdateServiceCommand) Execute(args []string) error { cmd.Main(os.Getenv("CF_TRACE"), os.Args) return nil }
func (_ CreateBuildpackCommand) Execute(args []string) error { cmd.Main(os.Getenv("CF_TRACE"), os.Args) return nil }
func (_ DeleteOrphanedRoutesCommand) Execute(args []string) error { cmd.Main(os.Getenv("CF_TRACE"), os.Args) return nil }
func (_ CopySourceCommand) Execute(args []string) error { cmd.Main(os.Getenv("CF_TRACE"), os.Args) return nil }
func (_ UnbindSecurityGroupCommand) Execute(args []string) error { cmd.Main(os.Getenv("CF_TRACE"), os.Args) return nil }
func (_ SetHealthCheckCommand) Execute(args []string) error { cmd.Main(os.Getenv("CF_TRACE"), os.Args) return nil }
func (_ FeatureFlagCommand) Execute(args []string) error { cmd.Main(os.Getenv("CF_TRACE"), os.Args) return nil }
func (_ PurgeServiceOfferingCommand) Execute(args []string) error { cmd.Main(os.Getenv("CF_TRACE"), os.Args) return nil }