|
| 1 | +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | + |
| 3 | +package cmd |
| 4 | + |
| 5 | +import ( |
| 6 | + "context" |
| 7 | + "fmt" |
| 8 | + |
| 9 | + "github.com/stainless-api/stainless-api-go" |
| 10 | + "github.com/stainless-api/stainless-api-go/option" |
| 11 | + "github.com/tidwall/gjson" |
| 12 | + "github.com/urfave/cli/v3" |
| 13 | +) |
| 14 | + |
| 15 | +var specRetrieveDecoratedSpec = cli.Command{ |
| 16 | + Name: "retrieve-decorated-spec", |
| 17 | + Usage: "Retrieve the decorated spec for a given application and project.", |
| 18 | + Flags: []cli.Flag{ |
| 19 | + &cli.StringFlag{ |
| 20 | + Name: "client-id", |
| 21 | + }, |
| 22 | + &cli.StringFlag{ |
| 23 | + Name: "project-name", |
| 24 | + }, |
| 25 | + }, |
| 26 | + Action: handleSpecRetrieveDecoratedSpec, |
| 27 | + HideHelpCommand: true, |
| 28 | +} |
| 29 | + |
| 30 | +func handleSpecRetrieveDecoratedSpec(ctx context.Context, cmd *cli.Command) error { |
| 31 | + cc := getAPICommandContext(cmd) |
| 32 | + unusedArgs := cmd.Args().Slice() |
| 33 | + if !cmd.IsSet("project-name") && len(unusedArgs) > 0 { |
| 34 | + cmd.Set("project-name", unusedArgs[0]) |
| 35 | + unusedArgs = unusedArgs[1:] |
| 36 | + } |
| 37 | + if len(unusedArgs) > 0 { |
| 38 | + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) |
| 39 | + } |
| 40 | + params := stainless.SpecGetDecoratedSpecParams{} |
| 41 | + if cmd.IsSet("client-id") { |
| 42 | + params.ClientID = cmd.Value("client-id").(string) |
| 43 | + } |
| 44 | + var res []byte |
| 45 | + _, err := cc.client.Spec.GetDecoratedSpec( |
| 46 | + context.TODO(), |
| 47 | + cmd.Value("project-name").(string), |
| 48 | + params, |
| 49 | + option.WithMiddleware(cc.AsMiddleware()), |
| 50 | + option.WithResponseBodyInto(&res), |
| 51 | + ) |
| 52 | + if err != nil { |
| 53 | + return err |
| 54 | + } |
| 55 | + |
| 56 | + json := gjson.Parse(string(res)) |
| 57 | + format := cmd.Root().String("format") |
| 58 | + transform := cmd.Root().String("transform") |
| 59 | + return ShowJSON("spec retrieve-decorated-spec", json, format, transform) |
| 60 | +} |
0 commit comments