Skip to content

Commit 5f8e90e

Browse files
committed
[urfavecli] handle nil required
1 parent dae14c0 commit 5f8e90e

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ climate allows the server to influence the CLI behaviour by using OpenAPI's [ext
1818

1919
Overall, the way it works:
2020

21-
- Each operation is converted to a Cobra command
21+
- Each operation is converted to a Cobra or urfave/cli command
2222
- Each parameter is converted to a flag with its corresponding type
2323
- 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
2424
- The provided handlers are attached to each command, grouped and attached to the rootCmd

urfavecli.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,37 @@ func addParamsUrfaveCli(cmd *cli.Command, op *v3.Operation, handlerData *Handler
3232

3333
for _, param := range op.Parameters {
3434
t := getParamType(param, op)
35+
name := param.Name
36+
desc := param.Description
37+
required := false
38+
if req := param.Required; req != nil {
39+
required = *req
40+
}
3541

3642
switch t {
3743
case String:
3844
flags = append(flags, &cli.StringFlag{
39-
Name: param.Name,
40-
Usage: param.Description,
41-
Required: *param.Required,
45+
Name: name,
46+
Usage: desc,
47+
Required: required,
4248
})
4349
case Integer:
4450
flags = append(flags, &cli.IntFlag{
45-
Name: param.Name,
46-
Usage: param.Description,
47-
Required: *param.Required,
51+
Name: name,
52+
Usage: desc,
53+
Required: required,
4854
})
4955
case Number:
5056
flags = append(flags, &cli.Float64Flag{
51-
Name: param.Name,
52-
Usage: param.Description,
53-
Required: *param.Required,
57+
Name: name,
58+
Usage: desc,
59+
Required: required,
5460
})
5561
case Boolean:
5662
flags = append(flags, &cli.BoolFlag{
57-
Name: param.Name,
58-
Usage: param.Description,
59-
Required: *param.Required,
63+
Name: name,
64+
Usage: desc,
65+
Required: required,
6066
})
6167
default:
6268
// TODO: array, object

0 commit comments

Comments
 (0)