Skip to content

Commit 65ee6d2

Browse files
committed
[doc] better org
1 parent 350cd27 commit 65ee6d2

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

README.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,37 @@ What if you can influence the CLI behaviour from the server? This enables you to
1212

1313
## Getting started
1414

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-
3015
### Rationale
3116

3217
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.
3318

3419
Overall, the way it works:
20+
3521
- Each operation is converted to a Cobra command
3622
- Each parameter is converted to a flag with its corresponding type
3723
- 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
3824
- The provided handlers are attached to each command, grouped and attached to the rootCmd
3925

4026
Influenced by some of the ideas behind [restish](https://rest.sh/) it uses the following extensions as of now:
27+
4128
- `x-cli-aliases`: A list of strings which would be used as the alternate names for an operation
4229
- `x-cli-group`: A string to allow grouping subcommands together. All operations in the same group would become subcommands in that group name
4330
- `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
4431
- `x-cli-ignored`: A boolean to tell climate to omit the operation completely
4532
- `x-cli-name`: A string to specify a different name. Applies to operations and request bodies as of now
4633

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+
4746
### Usage
4847

4948
Given an OpenAPI spec like [api.yaml](/api.yaml)
@@ -65,6 +64,7 @@ rootCmd := &cobra.Command{
6564
```
6665

6766
Define one or more handler functions of the following signature:
67+
6868
```go
6969
func handler(opts *cobra.Command, args []string, data climate.HandlerData) error {
7070
slog.Info("called!", "data", fmt.Sprintf("%+v", data))
@@ -73,13 +73,15 @@ func handler(opts *cobra.Command, args []string, data climate.HandlerData) error
7373
return err
7474
}
7575
```
76+
7677
#### Handler Data
7778

7879
(Feedback welcome to make this better!)
7980

8081
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)
8182

8283
This can be used to query the params from the command mostly in a type safe manner:
84+
8385
```go
8486
// to get all the int path params
8587
for _, param := range data.PathParams {
@@ -182,6 +184,7 @@ $ go run main.go ops add-get --n1 1 --n2 2
182184
```
183185

184186
## License
187+
185188
Copyright © 2024- Rahul De
186189

187190
Distributed under the MIT License. See LICENSE.

0 commit comments

Comments
 (0)