33package main
44
55import (
6+ "bytes"
67 "context"
78 "fmt"
89 "io"
@@ -117,7 +118,8 @@ var buildsCreate = cli.Command{
117118 Action : getAPIFlagAction [bool ]("body" , "allow_empty" ),
118119 },
119120 & cli.BoolFlag {
120- Name : "wait" ,
121+ Name : "wait" ,
122+ Value : true ,
121123 },
122124 & cli.BoolFlag {
123125 Name : "pull" ,
@@ -236,24 +238,23 @@ var buildsCompare = cli.Command{
236238
237239func handleBuildsCreate (ctx context.Context , cmd * cli.Command ) error {
238240 cc := getAPICommandContext (ctx , cmd )
239- // Log to stderr that we're creating a build (using white text)
240- fmt .Fprintf (os .Stderr , "Creating build...\n " )
241+ // Log to stderr that we're creating a build
242+ fmt .Fprintf (os .Stderr , "%s Creating build...\n " , au . BrightCyan ( "✱" ) )
241243 params := stainlessv0.BuildNewParams {}
242244 res , err := cc .client .Builds .New (
243245 context .TODO (),
244246 params ,
245247 option .WithMiddleware (cc .AsMiddleware ()),
246- option .WithRequestBody ("application/json" , cc .body ),
247248 )
248249 if err != nil {
249250 return err
250251 }
251252
252- // Print the build ID to stderr (using white text)
253- fmt .Fprintf (os .Stderr , "Build created: %s\n " , res .ID )
253+ // Print the build ID to stderr
254+ fmt .Fprintf (os .Stderr , " %s Build created: %s\n " , au . BrightGreen ( "•" ), au . Bold ( res .ID ) )
254255
255256 if cmd .Bool ("wait" ) {
256- fmt .Fprintf (os .Stderr , "Waiting for build to complete...\n " )
257+ fmt .Fprintf (os .Stderr , "%s Waiting for build to complete...\n " , au . BrightCyan ( "✱" ) )
257258
258259 ticker := time .NewTicker (3 * time .Second )
259260 defer ticker .Stop ()
@@ -289,14 +290,15 @@ func handleBuildsCreate(ctx context.Context, cmd *cli.Command) error {
289290
290291 // Only print completed statuses with a green checkmark
291292 if isTargetCompleted (target .status ) {
292- fmt .Fprintf (os .Stderr , "%s Target %s: %s\n " ,
293- au .BrightGreen ("✓ " ),
293+ fmt .Fprintf (os .Stderr , " %s Target %s: %s\n " ,
294+ au .BrightGreen ("• " ),
294295 target .name ,
295296 string (target .status ))
296297 anyCompleted = true
297298 } else if target .status == "failed" {
298299 // For failures, use red text
299- fmt .Fprintf (os .Stderr , "Target %s: %s\n " ,
300+ fmt .Fprintf (os .Stderr , " %s Target %s: %s\n " ,
301+ au .BrightRed ("•" ),
300302 target .name ,
301303 au .BrightRed (string (target .status )))
302304 }
@@ -310,7 +312,7 @@ func handleBuildsCreate(ctx context.Context, cmd *cli.Command) error {
310312
311313 if (allCompleted || anyCompleted ) && len (targets ) > 0 {
312314 if allCompleted {
313- fmt .Fprintf (os .Stderr , "%s Build completed successfully\n " , au .BrightGreen ("✓ " ))
315+ fmt .Fprintf (os .Stderr , " %s Build completed successfully\n " , au .BrightGreen ("✱ " ))
314316 break loop
315317 }
316318 }
@@ -321,11 +323,11 @@ func handleBuildsCreate(ctx context.Context, cmd *cli.Command) error {
321323 }
322324
323325 if cmd .Bool ("pull" ) {
324- fmt .Fprintf (os .Stderr , "Pulling build outputs...\n " )
326+ fmt .Fprintf (os .Stderr , "%s Pulling build outputs...\n " , au . BrightCyan ( "✱" ) )
325327 if err := pullBuildOutputs (context .TODO (), cc .client , * res ); err != nil {
326- fmt .Fprintf (os .Stderr , "%s Failed to pull outputs: %v\n " , au .BrightRed ("! " ), err )
328+ fmt .Fprintf (os .Stderr , "%s Failed to pull outputs: %v\n " , au .BrightRed ("✱ " ), err )
327329 } else {
328- fmt .Fprintf (os .Stderr , "%s Successfully pulled all outputs\n " , au .BrightGreen ("✓ " ))
330+ fmt .Fprintf (os .Stderr , "%s Successfully pulled all outputs\n " , au .BrightGreen ("✱ " ))
329331 }
330332 }
331333 }
@@ -367,11 +369,12 @@ func pullBuildOutputs(ctx context.Context, client stainlessv0.Client, res stainl
367369 return fmt .Errorf ("no completed targets found in build %s" , res .ID )
368370 }
369371
370- fmt .Fprintf (os .Stderr , "Found completed targets: %v\n " , targets )
371-
372372 // Pull each target
373- for _ , target := range targets {
374- fmt .Fprintf (os .Stderr , "Pulling output for target: %s\n " , target )
373+ for i , target := range targets {
374+ targetDir := fmt .Sprintf ("%s-%s" , res .Project , target )
375+
376+ fmt .Fprintf (os .Stderr , "%s [%d/%d] Pulling %s → %s\n " ,
377+ au .BrightCyan ("✱" ), i + 1 , len (targets ), au .Bold (target ), au .Cyan (targetDir ))
375378
376379 // Get the output details
377380 outputRes , err := client .BuildTargetOutputs .Get (
@@ -384,57 +387,72 @@ func pullBuildOutputs(ctx context.Context, client stainlessv0.Client, res stainl
384387 },
385388 )
386389 if err != nil {
387- fmt .Fprintf (os .Stderr , "%s Error getting output for target %s: %v\n " , au .BrightRed ("!" ), target , err )
390+ fmt .Fprintf (os .Stderr , "%s Failed to get output details for %s: %v\n " ,
391+ au .BrightRed ("✱" ), target , err )
388392 continue
389393 }
390394
391- targetDir := fmt .Sprintf ("%s-sdk" , target )
392-
393395 // Handle based on output type
394- err = pullOutput (outputRes .Output , outputRes .URL , outputRes .Ref , targetDir )
396+ err = pullOutput (outputRes .Output , outputRes .URL , outputRes .Ref , targetDir , target )
395397 if err != nil {
396- fmt .Fprintf (os .Stderr , "%s Error pulling output for target %s: %v\n " , au .BrightRed ("!" ), target , err )
398+ fmt .Fprintf (os .Stderr , "%s Failed to pull %s: %v\n " ,
399+ au .BrightRed ("✱" ), target , err )
397400 continue
398- } else {
399- fmt .Fprintf (os .Stderr , "%s Successfully pulled output for target %s\n " , au .BrightGreen ("✓" ), target )
401+ }
402+
403+ fmt .Fprintf (os .Stderr , " %s Successfully pulled to %s\n " ,
404+ au .BrightBlack ("•" ), au .Cyan (targetDir ))
405+
406+ if i < len (targets )- 1 {
407+ fmt .Fprintf (os .Stderr , "\n " )
400408 }
401409 }
402410
403411 return nil
404412}
405413
406414// pullOutput handles downloading or cloning a build target output
407- func pullOutput (output , url , ref , targetDir string ) error {
408- // Create a directory for the output
415+ func pullOutput (output , url , ref , targetDir , target string ) error {
416+ // Remove existing directory if it exists
417+ if _ , err := os .Stat (targetDir ); err == nil {
418+ fmt .Fprintf (os .Stderr , " %s Removing existing directory %s\n " , au .BrightBlack ("•" ), targetDir )
419+ if err := os .RemoveAll (targetDir ); err != nil {
420+ return fmt .Errorf ("failed to remove existing directory %s: %v" , targetDir , err )
421+ }
422+ }
423+
424+ // Create a fresh directory for the output
409425 if err := os .MkdirAll (targetDir , 0755 ); err != nil {
410426 return fmt .Errorf ("failed to create directory %s: %v" , targetDir , err )
411427 }
412428
413429 switch output {
414430 case "git" :
415431 // Clone the repository
416- fmt .Fprintf (os .Stderr , "Cloning repository %s (ref: %s) to %s\n " , url , ref , targetDir )
432+ fmt .Fprintf (os .Stderr , " %s Cloning repository\n " , au .BrightBlack ("•" ))
433+ fmt .Fprintf (os .Stderr , " %s Checking out ref %s\n " , au .BrightBlack ("•" ), au .Bold (ref ))
417434
418435 cmd := exec .Command ("git" , "clone" , url , targetDir )
419- cmd .Stdout = os .Stderr
420- cmd .Stderr = os .Stderr
436+ var stderr bytes.Buffer
437+ cmd .Stdout = nil // Suppress git clone output
438+ cmd .Stderr = & stderr
421439 if err := cmd .Run (); err != nil {
422- return fmt .Errorf ("git clone failed: %v" , err )
440+ return fmt .Errorf ("git clone failed: %v\n Git error: %s " , err , stderr . String () )
423441 }
424442
425443 // Checkout the specific ref
426444 cmd = exec .Command ("git" , "-C" , targetDir , "checkout" , ref )
427- cmd .Stdout = os .Stderr
428- cmd .Stderr = os .Stderr
445+ stderr .Reset ()
446+ cmd .Stdout = nil // Suppress git checkout output
447+ cmd .Stderr = & stderr
429448 if err := cmd .Run (); err != nil {
430- return fmt .Errorf ("git checkout failed: %v" , err )
449+ return fmt .Errorf ("git checkout failed: %v\n Git error: %s " , err , stderr . String () )
431450 }
432451
433- fmt .Fprintf (os .Stderr , "%s Successfully cloned repository to %s\n " , au .BrightGreen ("✓" ), targetDir )
434-
435452 case "url" :
436453 // Download the tar file
437- fmt .Fprintf (os .Stderr , "Downloading from %s to %s\n " , url , targetDir )
454+ fmt .Fprintf (os .Stderr , " %s Downloading archive %s\n " , au .BrightBlack ("•" ), au .Underline (url ))
455+ fmt .Fprintf (os .Stderr , " %s Extracting to %s\n " , au .BrightBlack ("•" ), targetDir )
438456
439457 // Create a temporary file for the tar download
440458 tmpFile , err := os .CreateTemp ("" , "stainless-*.tar.gz" )
@@ -464,14 +482,12 @@ func pullOutput(output, url, ref, targetDir string) error {
464482
465483 // Extract the tar file
466484 cmd := exec .Command ("tar" , "-xzf" , tmpFile .Name (), "-C" , targetDir )
467- cmd .Stdout = os . Stderr
468- cmd .Stderr = os . Stderr
485+ cmd .Stdout = nil // Suppress tar output
486+ cmd .Stderr = nil
469487 if err := cmd .Run (); err != nil {
470488 return fmt .Errorf ("tar extraction failed: %v" , err )
471489 }
472490
473- fmt .Fprintf (os .Stderr , "%s Successfully downloaded and extracted to %s\n " , au .BrightGreen ("✓" ), targetDir )
474-
475491 default :
476492 return fmt .Errorf ("unsupported output type: %s. Supported types are 'git' and 'url'" , output )
477493 }
@@ -502,7 +518,6 @@ func handleBuildsCompare(ctx context.Context, cmd *cli.Command) error {
502518 context .TODO (),
503519 params ,
504520 option .WithMiddleware (cc .AsMiddleware ()),
505- option .WithRequestBody ("application/json" , cc .body ),
506521 )
507522 if err != nil {
508523 return err
0 commit comments