Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cmd/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
11 changes: 9 additions & 2 deletions cmd/retrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down
11 changes: 10 additions & 1 deletion pkg/output/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down Expand Up @@ -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] == '"' {
Expand Down
21 changes: 21 additions & 0 deletions pkg/output/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Loading