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
Copy file name to clipboardExpand all lines: README.md
+18-15Lines changed: 18 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -12,38 +12,37 @@ What if you can influence the CLI behaviour from the server? This enables you to
12
12
13
13
## Getting started
14
14
15
-
### Status
16
-
17
-
Alpha, looking for design/usage feedback!
18
-
19
-
### Ideally support:
20
-
- more of the OpenAPI types and their checks. eg arrays, enums, objects, multi types etc
21
-
- type checking request bodies of certain MIME types eg, `application/json`
22
-
- better handling of request bodies eg, providing a stdin or a curl like notation for a file `@payload.json` etc.
23
-
24
-
### Installation
25
-
26
-
```bash
27
-
go get github.com/lispyclouds/climate
28
-
```
29
-
30
15
### Rationale
31
16
32
17
climate allows the server to influence the CLI behaviour by using OpenAPI's [extensions](https://swagger.io/docs/specification/v3_0/openapi-extensions/). It encourages [spec-first](https://www.atlassian.com/blog/technology/spec-first-api-development) practices thereby keeping both users and maintenance manageable. It does just enough to handle the spec and nothing more.
33
18
34
19
Overall, the way it works:
20
+
35
21
- Each operation is converted to a Cobra command
36
22
- Each parameter is converted to a flag with its corresponding type
37
23
- As of now, request bodies are a flag and treated as a string regardless of MIME type. Name defaults to `climate-data` unless specified via `x-cli-name`. All subject to change
38
24
- The provided handlers are attached to each command, grouped and attached to the rootCmd
39
25
40
26
Influenced by some of the ideas behind [restish](https://rest.sh/) it uses the following extensions as of now:
27
+
41
28
-`x-cli-aliases`: A list of strings which would be used as the alternate names for an operation
42
29
-`x-cli-group`: A string to allow grouping subcommands together. All operations in the same group would become subcommands in that group name
43
30
-`x-cli-hidden`: A boolean to hide the operation from the CLI menu. Same behaviour as a cobra command hide: it's present and expects a handler
44
31
-`x-cli-ignored`: A boolean to tell climate to omit the operation completely
45
32
-`x-cli-name`: A string to specify a different name. Applies to operations and request bodies as of now
46
33
34
+
### Ideally support:
35
+
36
+
- more of the OpenAPI types and their checks. eg arrays, enums, objects, multi types etc
37
+
- type checking request bodies of certain MIME types eg, `application/json`
38
+
- better handling of request bodies eg, providing a stdin or a curl like notation for a file `@payload.json` etc.
39
+
40
+
### Installation
41
+
42
+
```bash
43
+
go get github.com/lispyclouds/climate
44
+
```
45
+
47
46
### Usage
48
47
49
48
Given an OpenAPI spec like [api.yaml](/api.yaml)
@@ -65,6 +64,7 @@ rootCmd := &cobra.Command{
65
64
```
66
65
67
66
Define one or more handler functions of the following signature:
As of now, each handler is called with the cobra command it was invoked with, the args and an extra `climate.HandlerData`, more info [here](https://pkg.go.dev/github.com/lispyclouds/climate#pkg-types)
81
82
82
83
This can be used to query the params from the command mostly in a type safe manner:
84
+
83
85
```go
84
86
// to get all the int path params
85
87
for_, param:=range data.PathParams {
@@ -182,6 +184,7 @@ $ go run main.go ops add-get --n1 1 --n2 2
0 commit comments