From a739b170b7bdca47c843dc4bc35a340a9faa4de4 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Thu, 15 Jan 2026 09:12:48 -0600 Subject: [PATCH 1/2] fix: output of `retrieve backup` looks like an error --- cmd/retrieve.go | 11 +++++++++-- pkg/output/main.go | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/cmd/retrieve.go b/cmd/retrieve.go index 89e29a48..f1619fa6 100644 --- a/cmd/retrieve.go +++ b/cmd/retrieve.go @@ -3,9 +3,10 @@ package cmd import ( "context" "fmt" - "github.com/uselagoon/lagoon-cli/pkg/output" "strings" + "github.com/uselagoon/lagoon-cli/pkg/output" + "github.com/spf13/cobra" "github.com/uselagoon/machinery/api/lagoon" lclient "github.com/uselagoon/machinery/api/lagoon/client" @@ -60,7 +61,13 @@ You can check the status of the backup using the list backups or get backup comm } return err } - resultData := output.Result{Result: fmt.Sprintf("successfully created restore with ID: %d", result.ID)} + resultData := output.Result{ + Result: "success", + ResultData: map[string]interface{}{ + "ID": result.ID, + "Status": "pending", + }, + } r := output.RenderResult(resultData, outputOptions) fmt.Fprintf(cmd.OutOrStdout(), "%s", r) } diff --git a/pkg/output/main.go b/pkg/output/main.go index b46edfce..d31b9a57 100644 --- a/pkg/output/main.go +++ b/pkg/output/main.go @@ -34,7 +34,7 @@ type Options struct { // Result . type Result struct { ResultData map[string]interface{} `json:"data,omitempty"` - Result string `json:"result,omitempty"` + Result string `json:"result,omitempty"` // `success` or warning/error message Error string `json:"error,omitempty"` Info string `json:"info,omitempty"` } From dd0ed3097ed502baacadc4eb136e43415ab0cdd2 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Thu, 15 Jan 2026 09:12:49 -0600 Subject: [PATCH 2/2] feat: output of `get backup` can be piped directly to curl/wget --- cmd/environment.go | 3 +-- pkg/output/main.go | 9 +++++++++ pkg/output/main_test.go | 21 +++++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/cmd/environment.go b/cmd/environment.go index 4311f1a1..4f37414b 100644 --- a/cmd/environment.go +++ b/cmd/environment.go @@ -268,8 +268,7 @@ This returns a direct URL to the backup, this is a signed download link with a l for _, backup := range backupsResult.Backups { if backup.BackupID == backupID { if backup.Restore.RestoreLocation != "" { - resultData := output.Result{Result: backup.Restore.RestoreLocation} - r := output.RenderResult(resultData, outputOptions) + r := output.RenderString(backup.Restore.RestoreLocation, outputOptions) fmt.Fprintf(cmd.OutOrStdout(), "%s", r) return nil } diff --git a/pkg/output/main.go b/pkg/output/main.go index d31b9a57..a0b20752 100644 --- a/pkg/output/main.go +++ b/pkg/output/main.go @@ -173,6 +173,15 @@ func RenderOutput(data Table, opts Options) string { } } +// RenderString renders a simple string with no extra formatting. +func RenderString(msg string, opts Options) string { + if opts.JSON { + return RenderJSON(trimQuotes(msg), opts) + } + + return fmt.Sprintf("%s\n", trimQuotes(msg)) +} + func trimQuotes(s string) string { if len(s) >= 2 { if s[0] == '"' && s[len(s)-1] == '"' { diff --git a/pkg/output/main_test.go b/pkg/output/main_test.go index 50a743b9..dfc0ec61 100644 --- a/pkg/output/main_test.go +++ b/pkg/output/main_test.go @@ -122,3 +122,24 @@ func TestRenderOutput(t *testing.T) { checkEqual(t, output, testSuccess2, " render output table stdout no header processing failed") } } + +func TestRenderString(t *testing.T) { + var testData = `Plain string message` + var testSuccess1 = "Plain string message\n" + + outputOptions := Options{ + Header: false, + CSV: false, + JSON: false, + Pretty: false, + } + + output := RenderString(testData, outputOptions) + checkEqual(t, output, testSuccess1, " render string processing failed") + + var testSuccess2 = `"Plain string message"` + outputOptions.JSON = true + + output = RenderString(testData, outputOptions) + checkEqual(t, output, testSuccess2, " render string json processing failed") +}