@@ -43,6 +43,7 @@ import (
4343 stack_new "github.com/nitrictech/cli/pkg/view/tui/commands/stack/new"
4444 stack_preview "github.com/nitrictech/cli/pkg/view/tui/commands/stack/preview"
4545 stack_select "github.com/nitrictech/cli/pkg/view/tui/commands/stack/select"
46+ stack_up "github.com/nitrictech/cli/pkg/view/tui/commands/stack/up"
4647 "github.com/nitrictech/cli/pkg/view/tui/components/list"
4748 "github.com/nitrictech/cli/pkg/view/tui/components/listprompt"
4849 "github.com/nitrictech/cli/pkg/view/tui/components/view"
@@ -371,9 +372,7 @@ var stackUpdateCmd = &cobra.Command{
371372 }
372373 }
373374
374- // Check if the thing is active
375-
376- confirmModel := listprompt .NewListPrompt (listprompt.ListPromptArgs {
375+ confirmModel := stack_preview .NewConfirmDeployment (listprompt.ListPromptArgs {
377376 Items : list .StringsToListItems ([]string {"confirm deployment" , "cancel" }),
378377 Tag : "deploy" ,
379378 Prompt : "Finished preview. Would you like to perform the deployment?" ,
@@ -382,84 +381,76 @@ var stackUpdateCmd = &cobra.Command{
382381 selection , err := teax .NewProgram (confirmModel ).Run ()
383382 tui .CheckErr (err )
384383
385- v := view .New ()
386- v .Break ()
387- fmt .Println ("" )
388-
389- stackSelection = selection .(listprompt.ListPrompt ).Choice ()
384+ stackSelection = selection .(stack_preview.ConfirmDeploymentModel ).Choice ()
390385 if stackSelection == "cancel" {
391- v .Addln ("Cancelling deployment" )
392- fmt .Println (v .Render ())
386+ fmt .Println ("Cancelled" )
393387 return
394388 }
395389
396- v .Addln ("Deployed" )
397- fmt .Println (v .Render ())
390+ eventChan , errorChan := deploymentClient .Up (& deploymentspb.DeploymentUpRequest {
391+ Spec : spec ,
392+ Attributes : attributesStruct ,
393+ Interactive : true ,
394+ })
395+
396+ // Step 5d. Communicate with server to share progress of update
397+ if isNonInteractive () {
398+ providerErrorDetected := false
399+
400+ fmt .Printf ("Deploying %s stack with provider %s\n " , stackConfig .Name , stackConfig .Provider )
401+ go func () {
402+ for update := range errorChan {
403+ fmt .Printf ("Error: %s\n " , update )
404+ providerErrorDetected = true
405+ }
406+ }()
407+
408+ go func () {
409+ for outMessage := range providerStdout {
410+ fmt .Printf ("%s: %s\n " , stackConfig .Provider , outMessage )
411+ }
412+ }()
413+
414+ // non-interactive environment
415+ for update := range eventChan {
416+ switch content := update .Content .(type ) {
417+ case * deploymentspb.DeploymentUpEvent_Message :
418+ fmt .Printf ("%s\n " , content .Message )
419+ case * deploymentspb.DeploymentUpEvent_Update :
420+ updateResType := ""
421+ updateResName := ""
422+ if content .Update .Id != nil {
423+ updateResType = content .Update .Id .Type .String ()
424+ updateResName = content .Update .Id .Name
425+ }
426+
427+ if updateResType == "" {
428+ updateResType = "Stack"
429+ }
430+ if updateResName == "" {
431+ updateResName = stackConfig .Name
432+ }
433+ if content .Update .SubResource != "" {
434+ updateResName = fmt .Sprintf ("%s:%s" , updateResName , content .Update .SubResource )
435+ }
436+
437+ fmt .Printf ("%s:%s [%s]:%s %s\n " , updateResType , updateResName , content .Update .Action , content .Update .Status , content .Update .Message )
438+ case * deploymentspb.DeploymentUpEvent_Result :
439+ fmt .Printf ("\n Result: %s\n " , content .Result .GetText ())
440+ }
441+ }
398442
399- // eventChan, errorChan := deploymentClient.Up(&deploymentspb.DeploymentUpRequest{
400- // Spec: spec,
401- // Attributes: attributesStruct,
402- // Interactive: true,
403- // })
404-
405- // // Step 5d. Communicate with server to share progress of update
406- // if isNonInteractive() {
407- // providerErrorDetected := false
408-
409- // fmt.Printf("Deploying %s stack with provider %s\n", stackConfig.Name, stackConfig.Provider)
410- // go func() {
411- // for update := range errorChan {
412- // fmt.Printf("Error: %s\n", update)
413- // providerErrorDetected = true
414- // }
415- // }()
416-
417- // go func() {
418- // for outMessage := range providerStdout {
419- // fmt.Printf("%s: %s\n", stackConfig.Provider, outMessage)
420- // }
421- // }()
422-
423- // // non-interactive environment
424- // for update := range eventChan {
425- // switch content := update.Content.(type) {
426- // case *deploymentspb.DeploymentUpEvent_Message:
427- // fmt.Printf("%s\n", content.Message)
428- // case *deploymentspb.DeploymentUpEvent_Update:
429- // updateResType := ""
430- // updateResName := ""
431- // if content.Update.Id != nil {
432- // updateResType = content.Update.Id.Type.String()
433- // updateResName = content.Update.Id.Name
434- // }
435-
436- // if updateResType == "" {
437- // updateResType = "Stack"
438- // }
439- // if updateResName == "" {
440- // updateResName = stackConfig.Name
441- // }
442- // if content.Update.SubResource != "" {
443- // updateResName = fmt.Sprintf("%s:%s", updateResName, content.Update.SubResource)
444- // }
445-
446- // fmt.Printf("%s:%s [%s]:%s %s\n", updateResType, updateResName, content.Update.Action, content.Update.Status, content.Update.Message)
447- // case *deploymentspb.DeploymentUpEvent_Result:
448- // fmt.Printf("\nResult: %s\n", content.Result.GetText())
449- // }
450- // }
451-
452- // // ensure the process exits with a non-zero status code after all messages are processed
453- // if providerErrorDetected {
454- // os.Exit(1)
455- // }
456- // } else {
457- // // interactive environment
458- // // Step 5e. Start the stack up view
459- // stackUp := stack_up.New(stackConfig.Provider, stackConfig.Name, eventChan, providerStdout, errorChan)
460- // _, err = teax.NewProgram(stackUp).Run()
461- // tui.CheckErr(err)
462- // }
443+ // ensure the process exits with a non-zero status code after all messages are processed
444+ if providerErrorDetected {
445+ os .Exit (1 )
446+ }
447+ } else {
448+ // interactive environment
449+ // Step 5e. Start the stack up view
450+ stackUp := stack_up .New (stackConfig .Provider , stackConfig .Name , eventChan , providerStdout , errorChan )
451+ _ , err = teax .NewProgram (stackUp ).Run ()
452+ tui .CheckErr (err )
453+ }
463454 },
464455 Args : cobra .MinimumNArgs (0 ),
465456 Aliases : []string {"up" },
@@ -990,7 +981,7 @@ func init() {
990981 stackUpdateCmd .Flags ().BoolVarP (& noBuilder , "no-builder" , "" , false , "don't create a buildx container" )
991982 stackUpdateCmd .Flags ().StringVarP (& envFile , "env-file" , "e" , "" , "--env-file config/.my-env" )
992983 stackUpdateCmd .Flags ().BoolVarP (& forceStack , "force" , "f" , false , "force override previous deployment" )
993- stackUpdateCmd .Flags ().BoolVarP (& skipPreview , "skip-preview" , "" , false , "ignore preview" )
984+ stackUpdateCmd .Flags ().BoolVarP (& skipPreview , "skip-preview" , "" , false , "skips the preview step of the deployment " )
994985 tui .CheckErr (AddOptions (stackUpdateCmd , false ))
995986
996987 // Delete Stack (Down)
0 commit comments