Developing cf CLI plug-ins

Page last updated:

You can create and install cf CLI plug-ins to provide custom commands. You can submit and share these plug-ins to the CF Community repository.

Prerequisite

To use plug-ins, you must use cf CLI v7 or later. For information about downloading, installing, and uninstalling tcf CLI commands, see Installing the Cloud Foundry Command Line Interface.

Creating a plug-in

To prepare to create a plug-in:

  1. Implement the predefined plug-in interface from plugin.go in the Cloud Foundry CLI repository on GitHub.

  2. Clone the Cloud Foundry CLI repository from GitHub. To create a plug-in, you need the basic GO plugin.

Initializing the plug-in

To initialize a plug-in:

  1. From within the main() method of your plug-in, call:

    plugin.Start(new(MyPluginStruct))
    

    The plugin.Start(...) function requires a new reference to the struct that implements the defined interface.

Invoking cf CLI commands

To invoke cf CLI commands,

  1. From within the Run(...) method of your plug-in, call:

    cliConnection.CliCommand([]args)
    

The Run(...) method receives the cliConnection as its first argument. The cliConnection.CliCommand([]args) returns the output printed by the command and an error.

The output is returned as a slice of strings. The error occurs if the call to the cf CLI command fails.

For more information, see Plug-in API in the Cloud Foundry CLI repository on GitHub.

Installing a plug-in

To install a plug-in:

  1. Run:

    cf install-plugin PATH-TO-PLUGIN-BINARY
    

    Where PATH-TO-PLUGIN-BINARY is the path to your plug-in binary.

For more information about developing plug-ins, see plugin_examples in the Cloud Foundry CLI repository on GitHub.

Create a pull request or raise an issue on the source for this page in GitHub