You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Lagoon allows users to create simple custom commands that can execute raw graphql queries or mutations. The response of these commands will be the JSON response from the API, so tools like `jq` can be used to parse the response.
4
+
5
+
These commands are meant for simple tasks, and may not perform complex things very well. In some cases, the defaults of a flag may not work as you intend them to.
6
+
7
+
> **_NOTE:_** as always, be careful with creating your own commands, especially mutations, as you must be 100% aware of the implications.
8
+
9
+
## Location
10
+
11
+
Custom commands must be saved to `${HOME}/.lagoon-cli/commands/${COMMAND_NAME}.yml`
12
+
13
+
## Layout of a command file
14
+
15
+
An example of the command file structure is as follows
16
+
```yaml
17
+
name: project-by-name
18
+
description: Query a project by name
19
+
query: |
20
+
query projectByName($name: String!) {
21
+
projectByName(name: $name) {
22
+
id
23
+
name
24
+
organization
25
+
openshift{
26
+
name
27
+
}
28
+
environments{
29
+
name
30
+
openshift{
31
+
name
32
+
}
33
+
}
34
+
}
35
+
}
36
+
flags:
37
+
- name: name
38
+
description: Project name to check
39
+
variable: name
40
+
type: String
41
+
required: true
42
+
```
43
+
44
+
* `name` is the name of the command that the user must enter, this should be unique
45
+
* `description` is some helpful information about this command
46
+
* `query` is the query or mutation that is run
47
+
* `flags` allows you to define your own flags
48
+
* `name` is the name of the flag, eg `--name`
49
+
* `description` is some helpful information about the flag
50
+
* `variable` is the name of the variable that will be passed to the graphql query of the same name
51
+
* `type` is the type, currently only `String`, `Int`, `Boolean` are supported
52
+
* `required` is if this flag is required or not
53
+
* `default` is the default value of the flag if defined
54
+
* `String` defaults to ""
55
+
* `Int` defaults to 0
56
+
* `Boolean` defaults to false.
57
+
58
+
# Usage
59
+
60
+
Once a command file has been created, they will appear as `Available Commands` of the top level `custom` command, similarly to below
61
+
62
+
```
63
+
$ lagoon custom
64
+
Usage:
65
+
lagoon custom [flags]
66
+
lagoon custom [command]
67
+
68
+
Aliases:
69
+
custom, cus, cust
70
+
71
+
Available Commands:
72
+
project-by-name Query a project by name
73
+
74
+
```
75
+
76
+
You can then call this command like so, and see the output of the command is the API JSON response
0 commit comments