-
Notifications
You must be signed in to change notification settings - Fork 49
/
develop-cli-plugins.html.md.erb
64 lines (35 loc) · 2.32 KB
/
develop-cli-plugins.html.md.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
---
title: Developing cf CLI plug-ins
owner: CLI
---
You can create and install Cloud Foundry Command Line Interface (cf CLI) plug-ins to provide custom commands. You can submit and share these plug-ins to the [CF Community repository](https://plugins.cloudfoundry.org/).
## <a id='prerequisite'></a> Prerequisite
To use plug-ins, you must use cf CLI v7 or later. For information about downloading, installing, and uninstalling cf CLI commands, see [Installing the Cloud Foundry Command Line Interface](install-go-cli.html).
## <a id='install-arch'></a> Creating a plug-in
To prepare to create a plug-in:
1. Implement the predefined plug-in interface from [plugin.go](https://github.com/cloudfoundry/cli/blob/master/plugin/plugin.go) in the Cloud Foundry CLI repository on GitHub.
1. Clone the [Cloud Foundry CLI repository](https://github.com/cloudfoundry/cli) from GitHub. To create a plug-in, you need the [basic GO plugin](https://github.com/cloudfoundry/cli/blob/master/plugin/plugin_examples/basic_plugin.go).
## <a id='initialize'></a> 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.
## <a id='invoke'></a> 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](https://github.com/cloudfoundry/cli/blob/master/plugin/plugin_examples/DOC.md) in the Cloud Foundry CLI repository on GitHub.
## <a id='install-plugin'></a> 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](https://github.com/cloudfoundry/cli/tree/master/plugin/plugin_examples) in the Cloud Foundry CLI repository on GitHub.