@@ -17,82 +17,49 @@ import (
1717 "github.com/stainless-api/stainless-api-go/option"
1818
1919 "github.com/tidwall/gjson"
20- "github.com/tidwall/sjson"
2120 "github.com/urfave/cli/v3"
2221)
2322
2423// parseTargetPaths processes target flags to extract target:path syntax with workspace config
2524// Returns a map of target names to their custom paths
26- func parseTargetPaths (workspaceConfig WorkspaceConfig ) map [stainless.Target ]string {
27- targetPaths : = make (map [stainless.Target ]string )
25+ func parseTargetPaths (workspaceConfig WorkspaceConfig , targetsSlice [] string ) ( downloadPaths map [stainless.Target ]string , targets []stainless. Target ) {
26+ downloadPaths = make (map [stainless.Target ]string )
2827
2928 // Check workspace configuration for target paths if loaded
3029 for targetName , targetConfig := range workspaceConfig .Targets {
3130 if targetConfig .OutputPath != "" {
32- targetPaths [stainless .Target (targetName )] = targetConfig .OutputPath
31+ downloadPaths [stainless .Target (targetName )] = targetConfig .OutputPath
3332 }
3433 }
3534
36- // Get the current JSON body with all mutations applied
37- body , _ , _ , err := jsonflag .ApplyMutations ([]byte ("{}" ), []byte ("{}" ), []byte ("{}" ))
38- if err != nil {
39- return targetPaths // If we can't parse, return map with workspace paths
40- }
41-
42- // Check if there are any targets in the body
43- targetsResult := gjson .GetBytes (body , "targets" )
44- if ! targetsResult .Exists () {
45- return targetPaths
46- }
47-
48- // Process the targets array
49- var cleanTargets []string
50- for _ , targetResult := range targetsResult .Array () {
51- target := targetResult .String ()
35+ // Process the targets array from the CLI
36+ for _ , target := range targetsSlice {
5237 cleanTarget , path := processSingleTarget (target )
53- cleanTargets = append (cleanTargets , cleanTarget )
38+ targets = append (targets , cleanTarget )
5439 if path != "" {
5540 // Command line target:path overrides workspace configuration
56- targetPaths [stainless .Target (cleanTarget )] = path
41+ downloadPaths [stainless .Target (cleanTarget )] = path
5742 }
5843 }
5944
60- // Update the JSON body with cleaned targets
61- if len (cleanTargets ) > 0 {
62- body , err = sjson .SetBytes (body , "targets" , cleanTargets )
63- if err != nil {
64- return targetPaths
65- }
66-
67- // Clear mutations and re-apply the cleaned JSON
68- jsonflag .ClearMutations ()
69-
70- // Re-register the cleaned body
71- bodyObj := gjson .ParseBytes (body )
72- bodyObj .ForEach (func (key , value gjson.Result ) bool {
73- jsonflag .Mutate (jsonflag .Body , key .String (), value .Value ())
74- return true
75- })
76- }
77-
78- return targetPaths
45+ return downloadPaths , targets
7946}
8047
8148// processSingleTarget extracts path from target:path and returns clean target name and path
82- func processSingleTarget (target string ) (string , string ) {
49+ func processSingleTarget (target string ) (stainless. Target , string ) {
8350 target = strings .TrimSpace (target )
8451 if ! strings .Contains (target , ":" ) {
85- return target , ""
52+ return stainless . Target ( target ) , ""
8653 }
8754
8855 parts := strings .SplitN (target , ":" , 2 )
8956 if len (parts ) != 2 {
90- return target , ""
57+ return stainless . Target ( target ) , ""
9158 }
9259
9360 targetName := strings .TrimSpace (parts [0 ])
9461 targetPath := strings .TrimSpace (parts [1 ])
95- return targetName , targetPath
62+ return stainless . Target ( targetName ) , targetPath
9663}
9764
9865var buildsCreate = cli.Command {
@@ -133,16 +100,6 @@ var buildsCreate = cli.Command{
133100 Name : "target" ,
134101 Usage : "Optional list of SDK targets to build. If not specified, all configured\n targets will be built." ,
135102 },
136- & jsonflag.JSONStringFlag {
137- Name : "target" ,
138- Config : jsonflag.JSONConfig {
139- Kind : jsonflag .Body ,
140- Path : "targets.-1" ,
141- },
142- Hidden : true ,
143- },
144- & jsonflag.JSONStringFlag {,
145- },
146103 },
147104 Action : handleBuildsCreate ,
148105 HideHelpCommand : true ,
@@ -176,37 +133,50 @@ var buildsCompare = cli.Command{
176133
177134func handleBuildsCreate (ctx context.Context , cmd * cli.Command ) error {
178135 client := stainless .NewClient (getDefaultRequestOptions (cmd )... )
136+
137+ wc := WorkspaceConfig {}
138+ if _ , err := wc .Find (); err != nil {
139+ console .Warn ("%s" , err )
140+ }
141+
179142 unusedArgs := cmd .Args ().Slice ()
180143 if len (unusedArgs ) > 0 {
181144 return fmt .Errorf ("Unexpected extra arguments: %v" , unusedArgs )
182145 }
183146
184147 // Handle file flags by reading files and mutating JSON body
185- if err := applyFileFlag (cmd , "openapi-spec" , "revision.openapi\\ .yml.content" ); err != nil {
148+ if err := convertFileFlag (cmd , "openapi-spec" , "revision.openapi\\ .yml.content" ); err != nil {
186149 return err
187150 }
188- if err := applyFileFlag (cmd , "stainless-config" , "revision.openapi\\ .stainless\\ .yml.content" ); err != nil {
151+ if err := convertFileFlag (cmd , "stainless-config" , "revision.openapi\\ .stainless\\ .yml.content" ); err != nil {
189152 return err
190153 }
191154
192155 buildGroup := console .Info ("Creating build..." )
193156 params := stainless.BuildNewParams {}
194- build , err := cc .client .Builds .New (
157+ if err := unmarshalStdinWithFlags (cmd , map [string ]string {
158+ "targets" : "targets" ,
159+ }, & params ); err != nil {
160+ return err
161+ }
162+
163+ downloadPaths , targets := parseTargetPaths (wc , cmd .StringSlice ("target" ))
164+ params .Targets = targets
165+
166+ build , err := client .Builds .New (
195167 ctx ,
196168 params ,
197- option .WithMiddleware (cc . AsMiddleware ( )),
169+ option .WithMiddleware (debugMiddleware ( cmd . Bool ( "debug" ) )),
198170 )
199171 if err != nil {
200172 return err
201173 }
202174
203175 buildGroup .Property ("build_id" , build .ID )
204176
205- downloadPaths := parseTargetPaths (cc .workspaceConfig )
206-
207177 if cmd .Bool ("wait" ) {
208178 console .Spacer ()
209- model := tea .Model (buildCompletionModel {cbuild .NewModel (cc . client , ctx , * build , downloadPaths )})
179+ model := tea .Model (buildCompletionModel {cbuild .NewModel (client , ctx , * build , downloadPaths )})
210180 model , err = tea .NewProgram (model ).Run ()
211181 if err != nil {
212182 console .Warn (err .Error ())
0 commit comments