github.com/sleungcy-sap/cli@v7.1.0+incompatible/plugin/plugin_examples/DOC.md (about) 1 2 ## Plugin API 3 We wrote the Plugin API to make it easy for plugins to consume output from calling CLI commands. Previously, plugins needed to parse the terminal output which was not optimal. Before we wrote the API, only 2 methods were available to plugins: 4 ``` 5 CliCommand() 6 CliCommandWithoutTerminalOutput() 7 ``` 8 9 Both commands returned the terminal output in a string array, which was hard to parse. Instead terminal output, the result of the API calls will be in an object which is much easier to parse. Our goal was to make the common resources readily available to plugins without parsing. 10 11 12 13 14 Latest Available API Commands 15 ```go 16 17 /****************************************************************** 18 returns the output printed by the command and an error. 19 The output is returned as a slice of strings. 20 The error will be present if the call to the CLI command fails. 21 ******************************************************************/ 22 CliCommand(args ...string) ([]string, error) 23 24 /****************************************************************** 25 just like CliCommand but without the output in the terminal 26 ******************************************************************/ 27 CliCommandWithoutTerminalOutput(args ...string) ([]string, error) 28 29 GetCurrentOrg() (plugin_models.Organization, error) 30 31 GetCurrentSpace() (plugin_models.Space, error) 32 33 Username() (userName string, error) 34 35 UserGuid() (userGuid string, error) 36 37 UserEmail() (userEmail string, error) 38 39 IsLoggedIn() (bool, error) 40 41 IsSSLDisabled() (bool, error) 42 43 HasOrganization() (bool, error) 44 45 HasSpace() (bool, error) 46 47 ApiEndpoint() (endpointUrl string, error) 48 49 ApiVersion() (ver string, error) 50 51 HasAPIEndpoint() (bool, error) 52 53 LoggregatorEndpoint() (endpointUrl string, error) 54 55 DopplerEndpoint() (endpointUrl string, error) 56 57 AccessToken() (token string, error) 58 59 GetApp(string) (plugin_models.GetAppModel, error) 60 61 GetApps() ([]plugin_models.GetAppsModel, error) 62 63 GetOrgs() ([]plugin_models.GetOrgs_Model, error) 64 65 GetOrg(string) (plugin_models.GetOrg_Model, error) 66 67 GetSpaces() ([]plugin_models.GetSpaces_Model, error) 68 69 GetSpace(spaceName string) (plugin_models.GetSpace_Model, error) 70 71 /****************************************************************** 72 options takes the optional argument used in the `cf org` command, see `cf org -h` 73 ******************************************************************/ 74 GetOrgUsers(orgName string, options ...string) ([]plugin_models.GetOrgUsers_Model, error) 75 76 GetSpaceUsers(orgName string, spaceName string) ([]plugin_models.GetSpaceUsers_Model, error) 77 78 GetServices() ([]plugin_models.GetServices_Model, error) 79 80 GetService(serviceInstance string) (plugin_models.GetService_Model, error) 81 ``` 82 --- 83 Models return from APIs 84 - [Organization](https://github.com/cloudfoundry/cli/blob/master/plugin/models/get_current_org.go#L3) 85 - [Space](https://github.com/cloudfoundry/cli/blob/master/plugin/models/get_current_space.go#L3) 86 - [GetApp_Model](https://github.com/cloudfoundry/cli/blob/master/plugin/models/get_app.go#L5) 87 - [GetApps_Model](https://github.com/cloudfoundry/cli/blob/master/plugin/models/get_apps.go#L3) 88 - [GetOrgs_Model](https://github.com/cloudfoundry/cli/blob/master/plugin/models/get_orgs.go#L3) 89 - [GetOrg_Model](https://github.com/cloudfoundry/cli/blob/master/plugin/models/get_org.go#L3) 90 - [GetSpaces_Model](https://github.com/cloudfoundry/cli/blob/master/plugin/models/get_spaces.go#L3) 91 - [GetSpace_Model](https://github.com/cloudfoundry/cli/blob/master/plugin/models/get_space.go#L3) 92 - [GetOrgUsers_Model](https://github.com/cloudfoundry/cli/blob/master/plugin/models/get_org_users.go#L3) 93 - [GetSpaceUsers_Model](https://github.com/cloudfoundry/cli/blob/master/plugin/models/get_space_users.go#L3) 94 - [GetServices_Model](https://github.com/cloudfoundry/cli/blob/master/plugin/models/get_services.go#L3) 95 - [GetService_Model](https://github.com/cloudfoundry/cli/blob/master/plugin/models/get_service.go#L3)