Skip to content

Commit cf7e344

Browse files
chore(internal): codegen related update
1 parent 736a1de commit cf7e344

File tree

17 files changed

+332
-954
lines changed

17 files changed

+332
-954
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@ stl [resource] [command] [flags]
4545

4646
```sh
4747
stl builds create \
48-
--project stainless \
49-
--revision main
48+
<<JSON
49+
{
50+
"project": "stainless",
51+
"revision": "main"
52+
}
53+
JSON
5054
```
5155

5256
For details about specific commands, use the `--help` flag.

pkg/cmd/build.go

Lines changed: 20 additions & 198 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/stainless-api/stainless-api-cli/pkg/console"
1414
"github.com/stainless-api/stainless-api-cli/pkg/stainlessutils"
1515

16-
"github.com/stainless-api/stainless-api-cli/pkg/jsonflag"
1716
"github.com/stainless-api/stainless-api-go"
1817
"github.com/stainless-api/stainless-api-go/option"
1918

@@ -100,22 +99,6 @@ var buildsCreate = cli.Command{
10099
Name: "create",
101100
Usage: "Create a build, on top of a project branch, against a given input revision.",
102101
Flags: []cli.Flag{
103-
&jsonflag.JSONStringFlag{
104-
Name: "project",
105-
Usage: "Project name",
106-
Config: jsonflag.JSONConfig{
107-
Kind: jsonflag.Body,
108-
Path: "project",
109-
},
110-
},
111-
&jsonflag.JSONStringFlag{
112-
Name: "revision",
113-
Usage: `A branch name, commit SHA, or merge command in the format "base..head"`,
114-
Config: jsonflag.JSONConfig{
115-
Kind: jsonflag.Body,
116-
Path: "revision",
117-
},
118-
},
119102
&cli.StringFlag{
120103
Name: "openapi-spec",
121104
Aliases: []string{"oas"},
@@ -134,39 +117,21 @@ var buildsCreate = cli.Command{
134117
Name: "pull",
135118
Usage: "Pull the build outputs after completion (only works with --wait)",
136119
},
137-
&jsonflag.JSONBoolFlag{
120+
&cli.BoolFlag{
138121
Name: "allow-empty",
139122
Usage: "Whether to allow empty commits (no changes). Defaults to false.",
140-
Config: jsonflag.JSONConfig{
141-
Kind: jsonflag.Body,
142-
Path: "allow_empty",
143-
SetValue: true,
144-
},
145-
Value: false,
146123
},
147-
&jsonflag.JSONStringFlag{
124+
&cli.StringFlag{
148125
Name: "branch",
149126
Usage: "The project branch to use for the build. If not specified, the\nbranch is inferred from the `revision`, and will 400 when that\nis not possible.",
150-
Config: jsonflag.JSONConfig{
151-
Kind: jsonflag.Body,
152-
Path: "branch",
153-
},
154127
},
155-
&jsonflag.JSONStringFlag{
128+
&cli.StringFlag{
156129
Name: "commit-message",
157130
Usage: "Optional commit message to use when creating a new commit.",
158-
Config: jsonflag.JSONConfig{
159-
Kind: jsonflag.Body,
160-
Path: "commit_message",
161-
},
162131
},
163-
&jsonflag.JSONStringFlag{
164-
Name: "targets",
132+
&cli.StringSliceFlag{
133+
Name: "target",
165134
Usage: "Optional list of SDK targets to build. If not specified, all configured\ntargets will be built.",
166-
Config: jsonflag.JSONConfig{
167-
Kind: jsonflag.Body,
168-
Path: "targets.#",
169-
},
170135
},
171136
&jsonflag.JSONStringFlag{
172137
Name: "target",
@@ -176,13 +141,7 @@ var buildsCreate = cli.Command{
176141
},
177142
Hidden: true,
178143
},
179-
&jsonflag.JSONStringFlag{
180-
Name: "+target",
181-
Usage: "Optional list of SDK targets to build. If not specified, all configured\ntargets will be built.",
182-
Config: jsonflag.JSONConfig{
183-
Kind: jsonflag.Body,
184-
Path: "targets.-1",
185-
},
144+
&jsonflag.JSONStringFlag{,
186145
},
187146
},
188147
Action: handleBuildsCreate,
@@ -202,139 +161,21 @@ var buildsRetrieve = cli.Command{
202161
HideHelpCommand: true,
203162
}
204163

205-
var buildsList = cli.Command{
206-
Name: "list",
207-
Usage: "List user-triggered builds for a given project.",
208-
Flags: []cli.Flag{
209-
&jsonflag.JSONStringFlag{
210-
Name: "project",
211-
Usage: "Project name",
212-
Config: jsonflag.JSONConfig{
213-
Kind: jsonflag.Query,
214-
Path: "project",
215-
},
216-
},
217-
&jsonflag.JSONStringFlag{
218-
Name: "branch",
219-
Usage: "Branch name",
220-
Config: jsonflag.JSONConfig{
221-
Kind: jsonflag.Query,
222-
Path: "branch",
223-
},
224-
},
225-
&jsonflag.JSONStringFlag{
226-
Name: "cursor",
227-
Usage: "Pagination cursor from a previous response.",
228-
Config: jsonflag.JSONConfig{
229-
Kind: jsonflag.Query,
230-
Path: "cursor",
231-
},
232-
},
233-
&jsonflag.JSONFloatFlag{
234-
Name: "limit",
235-
Usage: "Maximum number of builds to return, defaults to 10 (maximum: 100).",
236-
Config: jsonflag.JSONConfig{
237-
Kind: jsonflag.Query,
238-
Path: "limit",
239-
},
240-
Value: 10,
241-
},
242-
&jsonflag.JSONStringFlag{
243-
Name: "revision",
244-
Usage: "A config commit SHA used for the build",
245-
Config: jsonflag.JSONConfig{
246-
Kind: jsonflag.Query,
247-
Path: "revision",
248-
},
249-
},
250-
},
251-
Action: handleBuildsList,
252-
HideHelpCommand: true,
253-
}
254-
255164
var buildsCompare = cli.Command{
256165
Name: "compare",
257166
Usage: "Create two builds whose outputs can be directly compared with each other.",
258167
Flags: []cli.Flag{
259-
&jsonflag.JSONStringFlag{
260-
Name: "base.branch",
261-
Usage: "Branch to use. When using a branch name as revision, this must match or be\nomitted.",
262-
Config: jsonflag.JSONConfig{
263-
Kind: jsonflag.Body,
264-
Path: "base.branch",
265-
},
266-
},
267-
&jsonflag.JSONStringFlag{
268-
Name: "base.revision",
269-
Usage: `A branch name, commit SHA, or merge command in the format "base..head"`,
270-
Config: jsonflag.JSONConfig{
271-
Kind: jsonflag.Body,
272-
Path: "base.revision",
273-
},
274-
},
275-
&jsonflag.JSONStringFlag{
276-
Name: "base.commit_message",
277-
Usage: "Optional commit message to use when creating a new commit.",
278-
Config: jsonflag.JSONConfig{
279-
Kind: jsonflag.Body,
280-
Path: "base.commit_message",
281-
},
282-
},
283-
&jsonflag.JSONStringFlag{
284-
Name: "head.branch",
285-
Usage: "Branch to use. When using a branch name as revision, this must match or be\nomitted.",
286-
Config: jsonflag.JSONConfig{
287-
Kind: jsonflag.Body,
288-
Path: "head.branch",
289-
},
290-
},
291-
&jsonflag.JSONStringFlag{
292-
Name: "head.revision",
293-
Usage: `A branch name, commit SHA, or merge command in the format "base..head"`,
294-
Config: jsonflag.JSONConfig{
295-
Kind: jsonflag.Body,
296-
Path: "head.revision",
297-
},
298-
},
299-
&jsonflag.JSONStringFlag{
300-
Name: "head.commit_message",
301-
Usage: "Optional commit message to use when creating a new commit.",
302-
Config: jsonflag.JSONConfig{
303-
Kind: jsonflag.Body,
304-
Path: "head.commit_message",
305-
},
306-
},
307-
&jsonflag.JSONStringFlag{
308-
Name: "project",
309-
Usage: "Project name",
310-
Config: jsonflag.JSONConfig{
311-
Kind: jsonflag.Body,
312-
Path: "project",
313-
},
314-
},
315-
&jsonflag.JSONStringFlag{
316-
Name: "targets",
317-
Usage: "Optional list of SDK targets to build. If not specified, all configured\ntargets will be built.",
318-
Config: jsonflag.JSONConfig{
319-
Kind: jsonflag.Body,
320-
Path: "targets.#",
321-
},
322-
},
323-
&jsonflag.JSONStringFlag{
324-
Name: "+target",
168+
&cli.StringSliceFlag{
169+
Name: "target",
325170
Usage: "Optional list of SDK targets to build. If not specified, all configured\ntargets will be built.",
326-
Config: jsonflag.JSONConfig{
327-
Kind: jsonflag.Body,
328-
Path: "targets.-1",
329-
},
330171
},
331172
},
332173
Action: handleBuildsCompare,
333174
HideHelpCommand: true,
334175
}
335176

336177
func handleBuildsCreate(ctx context.Context, cmd *cli.Command) error {
337-
cc := getAPICommandContext(cmd)
178+
client := stainless.NewClient(getDefaultRequestOptions(cmd)...)
338179
unusedArgs := cmd.Args().Slice()
339180
if len(unusedArgs) > 0 {
340181
return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs)
@@ -422,7 +263,7 @@ func (c buildCompletionModel) View() string {
422263
}
423264

424265
func handleBuildsRetrieve(ctx context.Context, cmd *cli.Command) error {
425-
cc := getAPICommandContext(cmd)
266+
client := stainless.NewClient(getDefaultRequestOptions(cmd)...)
426267
unusedArgs := cmd.Args().Slice()
427268
if !cmd.IsSet("build-id") && len(unusedArgs) > 0 {
428269
cmd.Set("build-id", unusedArgs[0])
@@ -432,10 +273,10 @@ func handleBuildsRetrieve(ctx context.Context, cmd *cli.Command) error {
432273
return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs)
433274
}
434275
var res []byte
435-
_, err := cc.client.Builds.Get(
276+
_, err := client.Builds.Get(
436277
ctx,
437278
cmd.Value("build-id").(string),
438-
option.WithMiddleware(cc.AsMiddleware()),
279+
option.WithMiddleware(debugMiddleware(cmd.Bool("debug"))),
439280
option.WithResponseBodyInto(&res),
440281
)
441282
if err != nil {
@@ -448,42 +289,23 @@ func handleBuildsRetrieve(ctx context.Context, cmd *cli.Command) error {
448289
return ShowJSON("builds retrieve", json, format, transform)
449290
}
450291

451-
func handleBuildsList(ctx context.Context, cmd *cli.Command) error {
452-
cc := getAPICommandContext(cmd)
453-
unusedArgs := cmd.Args().Slice()
454-
if len(unusedArgs) > 0 {
455-
return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs)
456-
}
457-
params := stainless.BuildListParams{}
458-
var res []byte
459-
_, err := cc.client.Builds.List(
460-
ctx,
461-
params,
462-
option.WithMiddleware(cc.AsMiddleware()),
463-
option.WithResponseBodyInto(&res),
464-
)
465-
if err != nil {
466-
return err
467-
}
468-
469-
json := gjson.Parse(string(res))
470-
format := cmd.Root().String("format")
471-
transform := cmd.Root().String("transform")
472-
return ShowJSON("builds list", json, format, transform)
473-
}
474-
475292
func handleBuildsCompare(ctx context.Context, cmd *cli.Command) error {
476-
cc := getAPICommandContext(cmd)
293+
client := stainless.NewClient(getDefaultRequestOptions(cmd)...)
477294
unusedArgs := cmd.Args().Slice()
478295
if len(unusedArgs) > 0 {
479296
return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs)
480297
}
481298
params := stainless.BuildCompareParams{}
299+
if err := unmarshalStdinWithFlags(cmd, map[string]string{
300+
"targets": "targets",
301+
}, &params); err != nil {
302+
return err
303+
}
482304
var res []byte
483-
_, err := cc.client.Builds.Compare(
305+
_, err := client.Builds.Compare(
484306
ctx,
485307
params,
486-
option.WithMiddleware(cc.AsMiddleware()),
308+
option.WithMiddleware(debugMiddleware(cmd.Bool("debug"))),
487309
option.WithResponseBodyInto(&res),
488310
)
489311
if err != nil {

0 commit comments

Comments
 (0)