|
6 | 6 | [id="cli-writing-plugins_{context}"] |
7 | 7 | = Writing CLI plugins |
8 | 8 |
|
| 9 | +[role="_abstract"] |
9 | 10 | You can write a plugin for the |
10 | 11 | ifndef::openshift-rosa,openshift-rosa-hcp,openshift-dedicated[] |
11 | 12 | {product-title} |
12 | 13 | endif::openshift-rosa,openshift-rosa-hcp,openshift-dedicated[] |
13 | 14 | ifdef::openshift-rosa,openshift-rosa-hcp,openshift-dedicated[] |
14 | 15 | OpenShift |
15 | 16 | endif::openshift-rosa,openshift-rosa-hcp,openshift-dedicated[] |
16 | | -CLI in any programming language |
17 | | -or script that allows you to write command-line commands. Note that you can not |
18 | | -use a plugin to overwrite an existing `oc` command. |
| 17 | +CLI in any programming language or script that allows you to write command-line commands. Note that you cannot use a plugin to overwrite an existing `oc` command. |
19 | 18 |
|
20 | | -.Procedure |
| 19 | +This procedure creates a simple Bash plugin that prints a message to the terminal when the `oc foo` command is issued. |
21 | 20 |
|
22 | | -This procedure creates a simple Bash plugin that prints a message to the |
23 | | -terminal when the `oc foo` command is issued. |
| 21 | +.Procedure |
24 | 22 |
|
25 | 23 | . Create a file called `oc-foo`. |
26 | 24 | + |
27 | 25 | When naming your plugin file, keep the following in mind: |
28 | 26 |
|
29 | 27 | * The file must begin with `oc-` or `kubectl-` to be recognized as a |
30 | 28 | plugin. |
31 | | -* The file name determines the command that invokes the plugin. For example, a |
32 | | -plugin with the file name `oc-foo-bar` can be invoked by a command of |
33 | | -`oc foo bar`. You can also use underscores if you want the command to contain |
34 | | -dashes. For example, a plugin with the file name `oc-foo_bar` can be invoked |
35 | | -by a command of `oc foo-bar`. |
| 29 | +* The file name determines the command that invokes the plugin. For example, a plugin with the file name `oc-foo-bar` can be invoked by a command of `oc foo bar`. You can also use underscores if you want the command to contain dashes. For example, a plugin with the file name `oc-foo_bar` can be invoked by a command of `oc foo-bar`. |
36 | 30 |
|
37 | 31 | . Add the following contents to the file. |
38 | 32 | + |
|
56 | 50 |
|
57 | 51 | echo "I am a plugin named kubectl-foo" |
58 | 52 | ---- |
59 | | - |
| 53 | ++ |
60 | 54 | After you install this plugin for the |
61 | 55 | ifndef::openshift-rosa,openshift-rosa-hcp,openshift-dedicated[] |
62 | 56 | {product-title} |
63 | 57 | endif::openshift-rosa,openshift-rosa-hcp,openshift-dedicated[] |
64 | 58 | ifdef::openshift-rosa,openshift-rosa-hcp[] |
65 | 59 | OpenShift |
66 | 60 | endif::openshift-rosa,openshift-rosa-hcp[] |
67 | | -CLI, it can be invoked |
68 | | -using the `oc foo` command. |
| 61 | +CLI, it can be invoked using the `oc foo` command. |
69 | 62 |
|
70 | 63 | [role="_additional-resources"] |
71 | 64 | .Additional resources |
72 | 65 |
|
73 | | -* Review the link:https://github.com/kubernetes/sample-cli-plugin[Sample plugin repository] |
74 | | -for an example of a plugin written in Go. |
75 | | -* Review the link:https://github.com/kubernetes/cli-runtime/[CLI runtime repository] for a set of utilities to assist in writing plugins in Go. |
| 66 | +* link:https://github.com/kubernetes/sample-cli-plugin[Sample plugin repository] |
| 67 | +* link:https://github.com/kubernetes/cli-runtime/[CLI runtime repository] |
0 commit comments