From 356e527f1fdf642aa47b9413e5e72d13a682a5d7 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Sat, 28 Dec 2024 23:35:47 +0100 Subject: [PATCH] refactor!: upgrade/rollback vertical render / ui fixes See https://git.coopcloud.tech/toolshed/organising/issues/658 --- cli/app/upgrade.go | 1 - cli/internal/deploy.go | 56 ++++++++++++++++++++---------------------- pkg/recipe/files.go | 6 ++++- 3 files changed, 32 insertions(+), 31 deletions(-) diff --git a/cli/app/upgrade.go b/cli/app/upgrade.go index bee884ef..d1f84ac4 100644 --- a/cli/app/upgrade.go +++ b/cli/app/upgrade.go @@ -250,7 +250,6 @@ beforehand.`, } if showReleaseNotes { - fmt.Println() fmt.Print(releaseNotes) return } diff --git a/cli/internal/deploy.go b/cli/internal/deploy.go index 79a7fac9..37aed079 100644 --- a/cli/internal/deploy.go +++ b/cli/internal/deploy.go @@ -42,13 +42,13 @@ func NewVersionOverview( app appPkg.App, warnMessages []string, kind, - currentVersion, - chaosVersion, - newVersion, + deployedVersion, + deployedChaosVersion, + toDeployVersion, releaseNotes string) error { deployConfig := "compose.yml" if composeFiles, ok := app.Env["COMPOSE_FILE"]; ok { - deployConfig = strings.Join(strings.Split(composeFiles, ":"), "\n") + deployConfig = composeFiles } server := app.Server @@ -61,32 +61,30 @@ func NewVersionOverview( domain = config.NO_DOMAIN_DEFAULT } - body := strings.Builder{} - body.WriteString( - borderStyle.Render( - lipgloss.JoinVertical( - lipgloss.Center, - headerStyle.Render(fmt.Sprintf("%s OVERVIEW", strings.ToUpper(kind))), - lipgloss.JoinVertical( - lipgloss.Left, - horizontal(leftStyle.Render("SERVER"), " ", rightStyle.Render(server)), - horizontal(leftStyle.Render("DOMAIN"), " ", rightStyle.Render(domain)), - horizontal(leftStyle.Render("RECIPE"), " ", rightStyle.Render(app.Recipe.Name)), - horizontal(leftStyle.Render("CONFIG"), " ", rightStyle.Render(deployConfig)), - horizontal(leftStyle.Render("VERSION"), " ", rightStyle.Render(currentVersion)), - horizontal(leftStyle.Render("CHAOS"), " ", rightStyle.Render(chaosVersion)), - horizontal(leftStyle.Render("DEPLOY"), " ", rightStyle.Padding(0).Render(newVersion)), - ), - ), - ), - ) - fmt.Println(body.String()) + rows := [][]string{ + []string{"APP", domain}, + []string{"RECIPE", app.Recipe.Name}, + []string{"SERVER", server}, + []string{"DEPLOYED", deployedVersion}, + []string{"CURRENT CHAOS ", deployedChaosVersion}, + []string{fmt.Sprintf("TO %s", strings.ToUpper(kind)), toDeployVersion}, + []string{"CONFIG", deployConfig}, + } - if releaseNotes != "" && newVersion != "" { - fmt.Println() + overview := formatter.CreateOverview( + fmt.Sprintf("%s OVERVIEW", strings.ToUpper(kind)), + rows, + ) + + fmt.Println(overview) + + if releaseNotes != "" && toDeployVersion != "" { fmt.Print(releaseNotes) } else { - warnMessages = append(warnMessages, fmt.Sprintf("no release notes available for %s", newVersion)) + warnMessages = append( + warnMessages, + fmt.Sprintf("no release notes available for %s", toDeployVersion), + ) } for _, msg := range warnMessages { @@ -120,7 +118,7 @@ func DeployOverview( toDeployChaosVersion string) error { deployConfig := "compose.yml" if composeFiles, ok := app.Env["COMPOSE_FILE"]; ok { - deployConfig = strings.Join(strings.Split(composeFiles, ":"), "\n") + deployConfig = composeFiles } server := app.Server @@ -176,7 +174,7 @@ func UndeployOverview( chaosVersion string) error { deployConfig := "compose.yml" if composeFiles, ok := app.Env["COMPOSE_FILE"]; ok { - deployConfig = strings.Join(strings.Split(composeFiles, ":"), "\n") + deployConfig = composeFiles } server := app.Server diff --git a/pkg/recipe/files.go b/pkg/recipe/files.go index f092fff3..d3408fa4 100644 --- a/pkg/recipe/files.go +++ b/pkg/recipe/files.go @@ -6,6 +6,7 @@ import ( "path" "coopcloud.tech/abra/pkg/envfile" + "coopcloud.tech/abra/pkg/formatter" ) func (r Recipe) SampleEnv() (map[string]string, error) { @@ -29,7 +30,10 @@ func (r Recipe) GetReleaseNotes(version string) (string, error) { if err != nil { return "", err } - withTitle := fmt.Sprintf("%s release notes:\n%s", version, string(releaseNotes)) + + title := formatter.BoldStyle.Render(fmt.Sprintf("%s release notes:", version)) + withTitle := fmt.Sprintf("%s\n%s\n", title, releaseNotes) + return withTitle, nil }