@@ -4,13 +4,13 @@ package cmd
44
55import (
66 "context"
7+ "encoding/json"
78 "fmt"
89 "os"
910 "path"
1011 "strings"
1112
1213 tea "github.com/charmbracelet/bubbletea"
13- "github.com/goccy/go-yaml"
1414 "github.com/stainless-api/stainless-api-cli/internal/apiquery"
1515 "github.com/stainless-api/stainless-api-cli/internal/requestflag"
1616 cbuild "github.com/stainless-api/stainless-api-cli/pkg/components/build"
@@ -19,6 +19,7 @@ import (
1919 "github.com/stainless-api/stainless-api-go"
2020 "github.com/stainless-api/stainless-api-go/option"
2121 "github.com/tidwall/gjson"
22+ "github.com/tidwall/sjson"
2223 "github.com/urfave/cli/v3"
2324)
2425
@@ -194,6 +195,25 @@ var buildsCompare = cli.Command{
194195 HideHelpCommand : true ,
195196}
196197
198+ func modifyYAML (cmd * cli.Command , key string , path string , value any ) (err error ) {
199+ b := []byte ("{}" )
200+
201+ if cmd .IsSet (key ) {
202+ v := cmd .Value (key )
203+ b , err = json .Marshal (v )
204+ if err != nil {
205+ return err
206+ }
207+ }
208+
209+ b , err = sjson .SetBytes (b , path , value )
210+ if err != nil {
211+ return err
212+ }
213+
214+ return cmd .Set ("revision" , string (b ))
215+ }
216+
197217func handleBuildsCreate (ctx context.Context , cmd * cli.Command ) error {
198218 var err error
199219 client := stainless .NewClient (getDefaultRequestOptions (cmd )... )
@@ -208,44 +228,21 @@ func handleBuildsCreate(ctx context.Context, cmd *cli.Command) error {
208228
209229 buildGroup := console .Info ("Creating build..." )
210230
211- var revision map [string ]map [string ]map [string ][]byte
212- if cmd .IsSet ("revision" ) {
213- var ok bool
214- revision , ok = cmd .Value ("revision" ).(map [string ]map [string ]map [string ][]byte )
215- if ! ok {
216- revision = make (map [string ]map [string ]map [string ][]byte )
217- }
218- } else {
219- revision = make (map [string ]map [string ]map [string ][]byte )
220- }
221- var exists bool
222- var fileInputMap map [string ]map [string ][]byte
223- if fileInputMap , exists = revision ["file_input_map" ]; ! exists {
224- fileInputMap = make (map [string ]map [string ][]byte )
225- revision ["file_input_map" ] = fileInputMap
226- }
227-
228231 if name , oas , err := convertFileFlag (cmd , "openapi-spec" ); err != nil {
229232 return err
230233 } else if oas != nil {
231- fileInputMap [ " openapi"+ path .Ext (name )] = map [string ][]byte {
234+ modifyYAML ( cmd , "revision" , gjson . Escape ( " openapi"+ path .Ext (name )), map [string ][]byte {
232235 "content" : oas ,
233- }
236+ })
234237 }
235238
236239 if name , config , err := convertFileFlag (cmd , "stainless-config" ); err != nil {
237240 return err
238241 } else if config != nil {
239- revision [ "file_input_map" ][ " stainless"+ path .Ext (name )] = map [string ][]byte {
242+ modifyYAML ( cmd , " revision" , gjson . Escape ( " stainless"+ path .Ext (name )), map [string ][]byte {
240243 "content" : config ,
241- }
242- }
243-
244- var revisionYAML []byte
245- if revisionYAML , err = yaml .Marshal (revision ); err != nil {
246- return err
244+ })
247245 }
248- cmd .Set ("revision" , string (revisionYAML ))
249246
250247 downloadPaths , targets , specifiedPath := parseTargetPaths (wc , cmd .StringSlice ("target" ))
251248
0 commit comments