@@ -11,10 +11,10 @@ import (
1111 "path"
1212 "strings"
1313
14- tea "github.com/charmbracelet/bubbletea"
1514 "github.com/stainless-api/stainless-api-cli/internal/apiquery"
1615 "github.com/stainless-api/stainless-api-cli/internal/requestflag"
1716 cbuild "github.com/stainless-api/stainless-api-cli/pkg/components/build"
17+ cdev "github.com/stainless-api/stainless-api-cli/pkg/components/dev"
1818 "github.com/stainless-api/stainless-api-cli/pkg/console"
1919 "github.com/stainless-api/stainless-api-cli/pkg/stainlessutils"
2020 "github.com/stainless-api/stainless-api-cli/pkg/workspace"
@@ -25,24 +25,15 @@ import (
2525 "github.com/urfave/cli/v3"
2626)
2727
28- // WaitMode represents the level of waiting for build completion
29- type WaitMode int
30-
31- const (
32- WaitNone WaitMode = iota // Don't wait
33- WaitCommit // Wait for commit only
34- WaitAll // Wait for everything including workflows
35- )
36-
3728// parseWaitMode converts the --wait flag string to a WaitMode
38- func parseWaitMode (wait string ) (WaitMode , error ) {
29+ func parseWaitMode (wait string ) (cdev. WaitMode , error ) {
3930 switch wait {
4031 case "none" , "false" : // Accept both "none" and "false" for backwards compatibility
41- return WaitNone , nil
32+ return cdev . WaitNone , nil
4233 case "commit" :
43- return WaitCommit , nil
34+ return cdev . WaitCommit , nil
4435 case "all" :
45- return WaitAll , nil
36+ return cdev . WaitAll , nil
4637 default :
4738 return 0 , fmt .Errorf ("invalid --wait value: %q (must be 'none', 'commit', or 'all')" , wait )
4839 }
@@ -429,20 +420,26 @@ func handleBuildsCreate(ctx context.Context, cmd *cli.Command) error {
429420
430421 buildGroup .Property ("build_id" , build .ID )
431422
432- if waitMode > WaitNone {
423+ if waitMode > cdev . WaitNone {
433424 console .Spacer ()
434- buildModel := cbuild .NewModel (client , ctx , * build , cmd .String ("branch" ), downloadPaths )
435- buildModel .CommitOnly = waitMode == WaitCommit
436- model := tea .Model (buildCompletionModel {
437- Build : buildModel ,
438- WaitMode : waitMode ,
425+ devModel := cdev .NewModel (cdev.ModelConfig {
426+ Client : client ,
427+ Ctx : ctx ,
428+ Branch : cmd .String ("branch" ),
429+ Start : func () (* stainless.Build , error ) { return build , nil },
430+ DownloadPaths : downloadPaths ,
431+ Label : "BUILD" ,
432+ WaitMode : waitMode ,
433+ Indent : " " ,
439434 })
440- model , err = console .NewProgram (model ).Run ()
435+ devModel .Build .CommitOnly = waitMode == cdev .WaitCommit
436+ model , err := console .NewProgram (devModel ).Run ()
441437 if err != nil {
442438 console .Warn ("%s" , err .Error ())
443439 }
444- b := model .(buildCompletionModel ).Build
445- build = & b .Build
440+ if m , ok := model .(cdev.Model ); ok {
441+ build = & m .Build .Build
442+ }
446443 console .Spacer ()
447444 }
448445
@@ -454,7 +451,7 @@ func handleBuildsCreate(ctx context.Context, cmd *cli.Command) error {
454451 }
455452
456453 // Only check for failures if we waited for the build
457- if waitMode == WaitNone {
454+ if waitMode == cdev . WaitNone {
458455 return nil
459456 }
460457
@@ -475,7 +472,7 @@ func handleBuildsCreate(ctx context.Context, cmd *cli.Command) error {
475472 }
476473
477474 // Only check workflow failures if we waited for them
478- if waitMode >= WaitAll {
475+ if waitMode >= cdev . WaitAll {
479476 if bt .Lint .Conclusion == "failure" || bt .Test .Conclusion == "failure" || bt .Build .Conclusion == "failure" {
480477 failures = append (failures , fmt .Errorf ("%s workflow failed" , target ))
481478 }
@@ -489,65 +486,6 @@ func handleBuildsCreate(ctx context.Context, cmd *cli.Command) error {
489486 return nil
490487}
491488
492- type buildCompletionModel struct {
493- Build cbuild.Model
494- WaitMode WaitMode
495- }
496-
497- func (c buildCompletionModel ) Init () tea.Cmd {
498- return c .Build .Init ()
499- }
500-
501- func (c buildCompletionModel ) Update (msg tea.Msg ) (tea.Model , tea.Cmd ) {
502- var cmd tea.Cmd
503- c .Build , cmd = c .Build .Update (msg )
504-
505- if c .IsCompleted () {
506- return c , tea .Sequence (
507- cmd ,
508- tea .Quit ,
509- )
510- }
511-
512- return c , cmd
513- }
514-
515- func (c buildCompletionModel ) IsCompleted () bool {
516- b := stainlessutils .NewBuild (c .Build .Build )
517- for _ , target := range b .Languages () {
518- buildTarget := b .BuildTarget (target )
519-
520- if buildTarget == nil {
521- return false
522- }
523-
524- // Check if download is completed (if applicable)
525- downloadIsCompleted := true
526- if buildTarget .IsCommitCompleted () && buildTarget .IsGoodCommitConclusion () {
527- if download , ok := c .Build .Downloads [target ]; ok {
528- downloadIsCompleted = download .Status == "completed"
529- }
530- }
531-
532- // Check if target is done based on wait mode
533- done := buildTarget .IsCommitCompleted ()
534- if c .WaitMode >= WaitAll {
535- done = buildTarget .IsCompleted ()
536- }
537-
538- if ! done || ! downloadIsCompleted {
539- return false
540- }
541- }
542-
543- return true
544- }
545-
546- func (c buildCompletionModel ) View () string {
547- c .Build .CommitOnly = c .WaitMode == WaitCommit
548- return c .Build .View ()
549- }
550-
551489func handleBuildsRetrieve (ctx context.Context , cmd * cli.Command ) error {
552490 client := stainless .NewClient (getDefaultRequestOptions (cmd )... )
553491 unusedArgs := cmd .Args ().Slice ()
0 commit comments