From cfd9b31df7dfaa32a19121d44523a73738fd8168 Mon Sep 17 00:00:00 2001 From: unclegedd Date: Mon, 1 Apr 2024 11:23:04 -0500 Subject: [PATCH] fix: adds global GracefulPanic and checks to deploy TUI --- main.go | 2 ++ src/cmd/uds.go | 40 +++++++++++++++--------------- src/pkg/bundle/tui/deploy/model.go | 4 +-- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/main.go b/main.go index 255515f3..6f00230d 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ import ( "embed" "github.com/defenseunicorns/uds-cli/src/cmd" + "github.com/defenseunicorns/uds-cli/src/pkg/utils" "github.com/defenseunicorns/zarf/src/pkg/packager/lint" ) @@ -15,6 +16,7 @@ import ( var zarfSchema embed.FS func main() { + defer utils.GracefulPanic() lint.ZarfSchema = zarfSchema cmd.Execute() } diff --git a/src/cmd/uds.go b/src/cmd/uds.go index 4ad4775f..0ca88107 100644 --- a/src/cmd/uds.go +++ b/src/cmd/uds.go @@ -112,26 +112,6 @@ var deployCmd = &cobra.Command{ }, } -func deployWithoutTea(bndlClient *bundle.Bundle) { - _, _, _, err := bndlClient.PreDeployValidation() - if err != nil { - message.Fatalf(err, "Failed to validate bundle: %s", err.Error()) - } - // confirm deployment - if ok := bndlClient.ConfirmBundleDeploy(); !ok { - message.Fatal(nil, "bundle deployment cancelled") - } - // create an empty program and kill it, this makes Program.Send a no-op - deploy.Program = tea.NewProgram(nil) - deploy.Program.Kill() - - // deploy the bundle - if err := bndlClient.Deploy(); err != nil { - bndlClient.ClearPaths() - message.Fatalf(err, "Failed to deploy bundle: %s", err.Error()) - } -} - var inspectCmd = &cobra.Command{ Use: "inspect [BUNDLE_TARBALL|OCI_REF]", Aliases: []string{"i"}, @@ -357,3 +337,23 @@ func chooseBundle(args []string) string { return path } + +func deployWithoutTea(bndlClient *bundle.Bundle) { + _, _, _, err := bndlClient.PreDeployValidation() + if err != nil { + message.Fatalf(err, "Failed to validate bundle: %s", err.Error()) + } + // confirm deployment + if ok := bndlClient.ConfirmBundleDeploy(); !ok { + message.Fatal(nil, "bundle deployment cancelled") + } + // create an empty program and kill it, this makes Program.Send a no-op + deploy.Program = tea.NewProgram(nil) + deploy.Program.Kill() + + // deploy the bundle + if err := bndlClient.Deploy(); err != nil { + bndlClient.ClearPaths() + message.Fatalf(err, "Failed to deploy bundle: %s", err.Error()) + } +} diff --git a/src/pkg/bundle/tui/deploy/model.go b/src/pkg/bundle/tui/deploy/model.go index 50835ee3..d9c0f29c 100644 --- a/src/pkg/bundle/tui/deploy/model.go +++ b/src/pkg/bundle/tui/deploy/model.go @@ -192,7 +192,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case tea.KeyMsg: switch msg.String() { case "y", "Y": - if !m.confirmed { + if !m.validatingBundle && !m.confirmed { m.confirmed = true m.inProgress = true } @@ -201,7 +201,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } case "n", "N": - if !m.confirmed && !m.inProgress { + if !m.validatingBundle && !m.confirmed && !m.inProgress { m.done = true quitMsg := tea.Println(tui.IndentStyle.Render("\nšŸ‘‹ Deployment cancelled")) return m, tea.Sequence(quitMsg, tea.Println(), tea.Quit)