Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.1.0-alpha.44"
".": "0.1.0-alpha.45"
}
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

## 0.1.0-alpha.45 (2025-10-02)

Full Changelog: [v0.1.0-alpha.44...v0.1.0-alpha.45](https://github.com/stainless-api/stainless-api-cli/compare/v0.1.0-alpha.44...v0.1.0-alpha.45)

### Features

* added `--output-filter` flag and `--error-format` flag to support better visualization options ([2768e5b](https://github.com/stainless-api/stainless-api-cli/commit/2768e5b0255ae79e44ed54f583c4809f19801afe))
* better support for positional arguments ([799d88f](https://github.com/stainless-api/stainless-api-cli/commit/799d88f441c5d1d5dca82a5590fceefdc1823f42))


### Chores

* **internal:** codegen related update ([2f9d764](https://github.com/stainless-api/stainless-api-cli/commit/2f9d764f660458d0e84e11adea9f1d418e8f1013))
* **internal:** codegen related update ([c7df1a7](https://github.com/stainless-api/stainless-api-cli/commit/c7df1a7401a51fe9657ca9fa7f1aff2d37f60851))

## 0.1.0-alpha.44 (2025-09-22)

Full Changelog: [v0.1.0-alpha.43...v0.1.0-alpha.44](https://github.com/stainless-api/stainless-api-cli/compare/v0.1.0-alpha.43...v0.1.0-alpha.44)
Expand Down
6 changes: 4 additions & 2 deletions cmd/stl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/stainless-api/stainless-api-cli/pkg/cmd"
"github.com/stainless-api/stainless-api-go"
"github.com/tidwall/gjson"
)

func main() {
Expand All @@ -19,8 +20,9 @@ func main() {
var apierr *stainless.Error
if errors.As(err, &apierr) {
fmt.Fprintf(os.Stderr, "%s %q: %d %s\n", apierr.Request.Method, apierr.Request.URL, apierr.Response.StatusCode, http.StatusText(apierr.Response.StatusCode))
format := app.String("format")
show_err := cmd.ShowJSON("Error", apierr.RawJSON(), format)
format := app.String("format-error")
json := gjson.Parse(apierr.RawJSON())
show_err := cmd.ShowJSON("Error", json, format, app.String("transform-error"))
if show_err != nil {
// Just print the original error:
fmt.Fprintf(os.Stderr, "%s\n", err.Error())
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/stainless-api/stainless-api-cli

go 1.24.0
go 1.24.4

toolchain go1.24.7

Expand All @@ -20,8 +20,8 @@ require (
github.com/tidwall/gjson v1.18.0
github.com/tidwall/pretty v1.2.1
github.com/tidwall/sjson v1.2.5
github.com/urfave/cli-docs/v3 v3.0.0-alpha6
github.com/urfave/cli/v3 v3.3.2
github.com/urfave/cli-docs/v3 v3.1.0
github.com/urfave/cli/v3 v3.4.1
golang.org/x/term v0.35.0
)

Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
github.com/urfave/cli-docs/v3 v3.0.0-alpha6 h1:w/l/N0xw1rO/aHRIGXJ0lDwwYFOzilup1qGvIytP3BI=
github.com/urfave/cli-docs/v3 v3.0.0-alpha6/go.mod h1:p7Z4lg8FSTrPB9GTaNyTrK3ygffHZcK3w0cU2VE+mzU=
github.com/urfave/cli/v3 v3.3.2 h1:BYFVnhhZ8RqT38DxEYVFPPmGFTEf7tJwySTXsVRrS/o=
github.com/urfave/cli/v3 v3.3.2/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo=
github.com/urfave/cli-docs/v3 v3.1.0 h1:Sa5xm19IpE5gpm6tZzXdfjdFxn67PnEsE4dpXF7vsKw=
github.com/urfave/cli-docs/v3 v3.1.0/go.mod h1:59d+5Hz1h6GSGJ10cvcEkbIe3j233t4XDqI72UIx7to=
github.com/urfave/cli/v3 v3.4.1 h1:1M9UOCy5bLmGnuu1yn3t3CB4rG79Rtoxuv1sPhnm6qM=
github.com/urfave/cli/v3 v3.4.1/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
github.com/yuin/goldmark v1.7.1/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
Expand Down
38 changes: 33 additions & 5 deletions pkg/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,10 @@ var buildsCompare = cli.Command{

func handleBuildsCreate(ctx context.Context, cmd *cli.Command) error {
cc := getAPICommandContext(cmd)
unusedArgs := cmd.Args().Slice()
if len(unusedArgs) > 0 {
return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs)
}

// Handle file flags by reading files and mutating JSON body
if err := applyFileFlag(cmd, "openapi-spec", "revision.openapi\\.yml.content"); err != nil {
Expand All @@ -459,7 +463,7 @@ func handleBuildsCreate(ctx context.Context, cmd *cli.Command) error {
if err != nil {
return err
}

buildGroup.Property("build_id", res.ID)

if cmd.Bool("wait") {
Expand All @@ -483,12 +487,22 @@ func handleBuildsCreate(ctx context.Context, cmd *cli.Command) error {
}
}

data := gjson.Parse(string(res.RawJSON()))
format := cmd.Root().String("format")
return ShowJSON("builds create", res.RawJSON(), format)
transform := cmd.Root().String("transform")
return ShowJSON("builds create", data, format, transform)
}

func handleBuildsRetrieve(ctx context.Context, cmd *cli.Command) error {
cc := getAPICommandContext(cmd)
unusedArgs := cmd.Args().Slice()
if !cmd.IsSet("build-id") && len(unusedArgs) > 0 {
cmd.Set("build-id", unusedArgs[0])
unusedArgs = unusedArgs[1:]
}
if len(unusedArgs) > 0 {
return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs)
}
var res []byte
_, err := cc.client.Builds.Get(
context.TODO(),
Expand All @@ -500,8 +514,10 @@ func handleBuildsRetrieve(ctx context.Context, cmd *cli.Command) error {
return err
}

json := gjson.Parse(string(res))
format := cmd.Root().String("format")
return ShowJSON("builds retrieve", string(res), format)
transform := cmd.Root().String("transform")
return ShowJSON("builds retrieve", json, format, transform)
}

// pullBuildOutputs pulls the outputs for a completed build
Expand Down Expand Up @@ -775,6 +791,10 @@ func pullOutput(output, url, ref, targetDir string, targetGroup *Group) error {

func handleBuildsList(ctx context.Context, cmd *cli.Command) error {
cc := getAPICommandContext(cmd)
unusedArgs := cmd.Args().Slice()
if len(unusedArgs) > 0 {
return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs)
}
params := stainless.BuildListParams{}
var res []byte
_, err := cc.client.Builds.List(
Expand All @@ -787,12 +807,18 @@ func handleBuildsList(ctx context.Context, cmd *cli.Command) error {
return err
}

json := gjson.Parse(string(res))
format := cmd.Root().String("format")
return ShowJSON("builds list", string(res), format)
transform := cmd.Root().String("transform")
return ShowJSON("builds list", json, format, transform)
}

func handleBuildsCompare(ctx context.Context, cmd *cli.Command) error {
cc := getAPICommandContext(cmd)
unusedArgs := cmd.Args().Slice()
if len(unusedArgs) > 0 {
return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs)
}
params := stainless.BuildCompareParams{}
var res []byte
_, err := cc.client.Builds.Compare(
Expand All @@ -805,6 +831,8 @@ func handleBuildsCompare(ctx context.Context, cmd *cli.Command) error {
return err
}

json := gjson.Parse(string(res))
format := cmd.Root().String("format")
return ShowJSON("builds compare", string(res), format)
transform := cmd.Root().String("transform")
return ShowJSON("builds compare", json, format, transform)
}
14 changes: 13 additions & 1 deletion pkg/cmd/builddiagnostic.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ package cmd

import (
"context"
"fmt"

"github.com/stainless-api/stainless-api-cli/pkg/jsonflag"
"github.com/stainless-api/stainless-api-go"
"github.com/stainless-api/stainless-api-go/option"
"github.com/tidwall/gjson"
"github.com/urfave/cli/v3"
)

Expand Down Expand Up @@ -60,6 +62,14 @@ var buildsDiagnosticsList = cli.Command{

func handleBuildsDiagnosticsList(ctx context.Context, cmd *cli.Command) error {
cc := getAPICommandContext(cmd)
unusedArgs := cmd.Args().Slice()
if !cmd.IsSet("build-id") && len(unusedArgs) > 0 {
cmd.Set("build-id", unusedArgs[0])
unusedArgs = unusedArgs[1:]
}
if len(unusedArgs) > 0 {
return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs)
}
params := stainless.BuildDiagnosticListParams{}
var res []byte
_, err := cc.client.Builds.Diagnostics.List(
Expand All @@ -73,6 +83,8 @@ func handleBuildsDiagnosticsList(ctx context.Context, cmd *cli.Command) error {
return err
}

json := gjson.Parse(string(res))
format := cmd.Root().String("format")
return ShowJSON("builds:diagnostics list", string(res), format)
transform := cmd.Root().String("transform")
return ShowJSON("builds:diagnostics list", json, format, transform)
}
11 changes: 10 additions & 1 deletion pkg/cmd/buildtargetoutput.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/stainless-api/stainless-api-cli/pkg/jsonflag"
"github.com/stainless-api/stainless-api-go"
"github.com/stainless-api/stainless-api-go/option"
"github.com/tidwall/gjson"
"github.com/urfave/cli/v3"
)

Expand Down Expand Up @@ -62,6 +63,10 @@ var buildsTargetOutputsRetrieve = cli.Command{

func handleBuildsTargetOutputsRetrieve(ctx context.Context, cmd *cli.Command) error {
cc := getAPICommandContext(cmd)
unusedArgs := cmd.Args().Slice()
if len(unusedArgs) > 0 {
return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs)
}

buildID := cmd.String("build-id")
if buildID == "" {
Expand All @@ -75,17 +80,21 @@ func handleBuildsTargetOutputsRetrieve(ctx context.Context, cmd *cli.Command) er
params := stainless.BuildTargetOutputGetParams{
BuildID: buildID,
}
var resBytes []byte
res, err := cc.client.Builds.TargetOutputs.Get(
context.TODO(),
params,
option.WithMiddleware(cc.AsMiddleware()),
option.WithResponseBodyInto(&resBytes),
)
if err != nil {
return err
}

json := gjson.Parse(string(resBytes))
format := cmd.Root().String("format")
if err := ShowJSON("builds:target_outputs retrieve", res.RawJSON(), format); err != nil {
transform := cmd.Root().String("transform")
if err := ShowJSON("builds:target_outputs retrieve", json, format, transform); err != nil {
return err
}

Expand Down
25 changes: 22 additions & 3 deletions pkg/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,34 @@ stl builds create --branch <branch>`,
},
&cli.StringFlag{
Name: "format",
Usage: "The format for data output (one of: " + strings.Join(OutputFormats[:], ", ") + ")",
Usage: "The format for displaying response data (one of: " + strings.Join(OutputFormats, ", ") + ")",
Value: "auto",
Validator: func(format string) error {
if !slices.Contains(OutputFormats[:], strings.ToLower(format)) {
return fmt.Errorf("format must be one of: %s", strings.Join(OutputFormats[:], ", "))
if !slices.Contains(OutputFormats, strings.ToLower(format)) {
return fmt.Errorf("format must be one of: %s", strings.Join(OutputFormats, ", "))
}
return nil
},
},
&cli.StringFlag{
Name: "format-error",
Usage: "The format for displaying error data (one of: " + strings.Join(OutputFormats, ", ") + ")",
Value: "auto",
Validator: func(format string) error {
if !slices.Contains(OutputFormats, strings.ToLower(format)) {
return fmt.Errorf("format must be one of: %s", strings.Join(OutputFormats, ", "))
}
return nil
},
},
&cli.StringFlag{
Name: "transform",
Usage: "The GJSON transformation for data output.",
},
&cli.StringFlag{
Name: "transform-error",
Usage: "The GJSON transformation for errors.",
},
&cli.StringFlag{
Name: "environment",
Usage: "Set the environment for API requests",
Expand Down
22 changes: 20 additions & 2 deletions pkg/cmd/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ package cmd

import (
"context"
"fmt"

"github.com/stainless-api/stainless-api-go/option"
"github.com/tidwall/gjson"
"github.com/urfave/cli/v3"
)

Expand All @@ -31,6 +33,14 @@ var orgsList = cli.Command{

func handleOrgsRetrieve(ctx context.Context, cmd *cli.Command) error {
cc := getAPICommandContext(cmd)
unusedArgs := cmd.Args().Slice()
if !cmd.IsSet("org") && len(unusedArgs) > 0 {
cmd.Set("org", unusedArgs[0])
unusedArgs = unusedArgs[1:]
}
if len(unusedArgs) > 0 {
return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs)
}
var res []byte
_, err := cc.client.Orgs.Get(
context.TODO(),
Expand All @@ -42,12 +52,18 @@ func handleOrgsRetrieve(ctx context.Context, cmd *cli.Command) error {
return err
}

json := gjson.Parse(string(res))
format := cmd.Root().String("format")
return ShowJSON("orgs retrieve", string(res), format)
transform := cmd.Root().String("transform")
return ShowJSON("orgs retrieve", json, format, transform)
}

func handleOrgsList(ctx context.Context, cmd *cli.Command) error {
cc := getAPICommandContext(cmd)
unusedArgs := cmd.Args().Slice()
if len(unusedArgs) > 0 {
return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs)
}
var res []byte
_, err := cc.client.Orgs.List(
context.TODO(),
Expand All @@ -58,6 +74,8 @@ func handleOrgsList(ctx context.Context, cmd *cli.Command) error {
return err
}

json := gjson.Parse(string(res))
format := cmd.Root().String("format")
return ShowJSON("orgs list", string(res), format)
transform := cmd.Root().String("transform")
return ShowJSON("orgs list", json, format, transform)
}
Loading
Loading