Developing cf CLI Plugins
Page last updated:
Users can create and install Cloud Foundry Command Line Interface (cf CLI) plugins to provide custom commands. These plugins can be submitted and shared to the CF Community repo.
Using plugins requires cf CLI v.6.7 or higher. Refer to the Installing the Cloud Foundry Command Line Interface topic for information about downloading, installing, and uninstalling the cf CLI.
Installing the Architecture
- Implement the predefined plugin interface.
- Clone the template repo. You will need the basic GO plugin.
Initializing the Plugin
To initialize a plugin, call
plugin.Start(new(MyPluginStruct)) from within
main() method of your plugin.
plugin.Start(...) function requires a new reference to the struct that
implements the defined interface.
Invoking CLI Commands
Invoke CLI commands with
cliConnection.CliCommand(args) from within a plugin’s
The Run(...) method receives the
cliConnection as its first argument.
cliConnection.CliCommand(args) returns the output printed by the command and an error.
The output is returned as a slice of strings. The error will be present if the call to the CLI command fails.
For more information, see the calling CLI commands example.
Installing a Plugin
To install a plugin, run
cf install-plugin PATH_TO_PLUGIN_BINARY.
For additional information about developing plugins, see the plugin development guide.