forked from cloudfoundry/docs-cf-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevelop-cli-plugins.html.md.erb
68 lines (37 loc) · 2.41 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
65
66
67
68
---
title: Developing cf CLI Plugins
owner: CLI
---
This topic describes creating and installing Cloud Foundry Command Line Interface (cf CLI) plugins.
## <a id='overview'></a> Overview
You can create and install cf CLI plugins to provide custom commands. You can submit and share these plugins to the [CF Community repository](https://plugins.cloudfoundry.org/).
## <a id='prerequisite'></a> Prerequisite
To use plugins, you must use cf CLI v.6.7 or later. For information about downloading, installing, and uninstalling the cf CLI, see [Installing the Cloud Foundry Command Line Interface](install-go-cli.html).
## <a id='install-arch'></a> Installing the Architecture
To prepare to create a plugin:
1. Implement the predefined plugin 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 plugin, 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 Plugin
To initialize a plugin:
1. From within the `main()` method of your plugin, 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 plugin, 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 [Plugin 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 Plugin
To install a plugin:
1. Run:
```
cf install-plugin PATH-TO-PLUGIN-BINARY
```
Where `PATH-TO-PLUGIN-BINARY` is the path to your plugin binary.
For more information about developing plugins, see [plugin_examples](https://github.com/cloudfoundry/cli/tree/master/plugin/plugin_examples) in the Cloud Foundry CLI repository on GitHub.