Skip to content

Commit b1ae8e7

Browse files
feat: use urfave/cli library
1 parent 24361de commit b1ae8e7

File tree

11 files changed

+515
-972
lines changed

11 files changed

+515
-972
lines changed

build.go

Lines changed: 113 additions & 273 deletions
Large diffs are not rendered by default.

buildtargetoutput.go

Lines changed: 34 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -4,102 +4,52 @@ package main
44

55
import (
66
"context"
7-
"flag"
87
"fmt"
9-
"net/http"
108
"os"
119

1210
"github.com/stainless-api/stainless-api-go"
1311
"github.com/stainless-api/stainless-api-go/option"
12+
"github.com/urfave/cli/v3"
1413
)
1514

16-
func createBuildTargetOutputsRetrieveSubcommand() Subcommand {
17-
query := []byte("{}")
18-
header := []byte("{}")
19-
var flagSet = flag.NewFlagSet("build_target_outputs.retrieve", flag.ExitOnError)
20-
21-
flagSet.Func(
22-
"build-id",
23-
"",
24-
func(string string) error {
25-
var jsonErr error
26-
query, jsonErr = jsonSet(query, "build_id", string)
27-
if jsonErr != nil {
28-
return jsonErr
29-
}
30-
return nil
15+
var buildTargetOutputsRetrieve = cli.Command{
16+
Name: "retrieve",
17+
Usage: "TODO",
18+
Flags: []cli.Flag{
19+
&cli.StringFlag{
20+
Name: "build-id",
21+
Action: getAPIFlagAction[string]("query", "build_id"),
3122
},
32-
)
33-
34-
flagSet.Func(
35-
"target",
36-
"",
37-
func(string string) error {
38-
var jsonErr error
39-
query, jsonErr = jsonSet(query, "target", string)
40-
if jsonErr != nil {
41-
return jsonErr
42-
}
43-
return nil
23+
&cli.StringFlag{
24+
Name: "target",
25+
Action: getAPIFlagAction[string]("query", "target"),
4426
},
45-
)
46-
47-
flagSet.Func(
48-
"type",
49-
"",
50-
func(string string) error {
51-
var jsonErr error
52-
query, jsonErr = jsonSet(query, "type", string)
53-
if jsonErr != nil {
54-
return jsonErr
55-
}
56-
return nil
27+
&cli.StringFlag{
28+
Name: "type",
29+
Action: getAPIFlagAction[string]("query", "type"),
5730
},
58-
)
59-
60-
flagSet.Func(
61-
"output",
62-
"",
63-
func(string string) error {
64-
var jsonErr error
65-
query, jsonErr = jsonSet(query, "output", string)
66-
if jsonErr != nil {
67-
return jsonErr
68-
}
69-
return nil
31+
&cli.StringFlag{
32+
Name: "output",
33+
Action: getAPIFlagAction[string]("query", "output"),
7034
},
71-
)
72-
73-
return Subcommand{
74-
flagSet: flagSet,
75-
handle: func(client *stainlessv0.Client) {
76-
res, err := client.BuildTargetOutputs.Get(
77-
context.TODO(),
78-
stainlessv0.BuildTargetOutputGetParams{},
79-
option.WithMiddleware(func(r *http.Request, mn option.MiddlewareNext) (*http.Response, error) {
80-
q := r.URL.Query()
81-
for key, values := range serializeQuery(query) {
82-
for _, value := range values {
83-
q.Add(key, value)
84-
}
85-
}
86-
r.URL.RawQuery = q.Encode()
87-
88-
for key, values := range serializeHeader(header) {
89-
for _, value := range values {
90-
r.Header.Add(key, value)
91-
}
92-
}
35+
},
36+
Before: initAPICommand,
37+
Action: handleBuildTargetOutputsRetrieve,
38+
HideHelpCommand: true,
39+
}
9340

94-
return mn(r)
95-
}),
96-
)
97-
if err != nil {
98-
fmt.Printf("%s\n", err)
99-
os.Exit(1)
100-
}
41+
func handleBuildTargetOutputsRetrieve(ctx context.Context, cmd *cli.Command) error {
42+
cc := getAPICommandContext(ctx, cmd)
10143

102-
fmt.Printf("%s\n", res.JSON.RawJSON())
103-
},
44+
res, err := cc.client.BuildTargetOutputs.Get(
45+
context.TODO(),
46+
stainlessv0.BuildTargetOutputGetParams{},
47+
option.WithMiddleware(cc.AsMiddleware()),
48+
)
49+
if err != nil {
50+
return err
10451
}
52+
53+
fmt.Printf("%s\n", colorizeJSON(res.RawJSON(), os.Stdout))
54+
return nil
10555
}

completions.fish

Lines changed: 0 additions & 66 deletions
This file was deleted.

completions.sh

Lines changed: 0 additions & 99 deletions
This file was deleted.

go.mod

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
module github.com/stainless-api/stainless-api-cli
22

3-
go 1.21
3+
go 1.23.0
4+
5+
toolchain go1.23.8
46

57
require (
68
github.com/stainless-api/stainless-api-go v0.1.1
7-
github.com/tidwall/gjson v1.14.4
9+
github.com/tidwall/gjson v1.17.0
10+
github.com/tidwall/pretty v1.2.1
811
github.com/tidwall/sjson v1.2.5
12+
github.com/urfave/cli/v3 v3.3.2
13+
golang.org/x/term v0.31.0
914
)
1015

1116
require (
1217
github.com/tidwall/match v1.1.1 // indirect
13-
github.com/tidwall/pretty v1.2.1 // indirect
18+
golang.org/x/sys v0.32.0 // indirect
1419
)

go.sum

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
15
github.com/stainless-api/stainless-api-go v0.1.1 h1:YrZuITXXMeOrQNK4ieLmqSG0sYWcMXQLNk22GmlkOBM=
26
github.com/stainless-api/stainless-api-go v0.1.1/go.mod h1:9Q2t8xq6EFgw8HYOsVxqKEfSDVe9eqCoh1zC0HMRwTY=
7+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
8+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
39
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
4-
github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM=
5-
github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
10+
github.com/tidwall/gjson v1.17.0 h1:/Jocvlh98kcTfpN2+JzGQWQcqrPQwDrVEMApx/M5ZwM=
11+
github.com/tidwall/gjson v1.17.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
612
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
713
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
814
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
915
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
1016
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
1117
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
1218
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
19+
github.com/urfave/cli/v3 v3.3.2 h1:BYFVnhhZ8RqT38DxEYVFPPmGFTEf7tJwySTXsVRrS/o=
20+
github.com/urfave/cli/v3 v3.3.2/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo=
21+
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
22+
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
23+
golang.org/x/term v0.31.0 h1:erwDkOK1Msy6offm1mOgvspSkslFnIGsFnxOKoufg3o=
24+
golang.org/x/term v0.31.0/go.mod h1:R4BeIy7D95HzImkxGkTW1UQTtP54tio2RyHz7PwK0aw=
25+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
26+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)