Skip to content

Commit

Permalink
Change: Updates the output for Render functions (#364)
Browse files Browse the repository at this point in the history
* refactor: output package return string

* Updates additional commands and tests

---------

Co-authored-by: shreddedbacon <[email protected]>
  • Loading branch information
CGoodwin90 and shreddedbacon authored Aug 5, 2024
1 parent 8dea96d commit 33d7950
Show file tree
Hide file tree
Showing 22 changed files with 346 additions and 229 deletions.
9 changes: 6 additions & 3 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ var configDefaultCmd = &cobra.Command{
"default-lagoon": lagoonConfig.Lagoon,
},
}
output.RenderResult(resultData, outputOptions)
r := output.RenderResult(resultData, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
},
}

Expand Down Expand Up @@ -129,10 +130,11 @@ var configLagoonsCmd = &cobra.Command{
tableHeader = append(tableHeader, "Kibana-URL")
}
tableHeader = append(tableHeader, "SSH-Key")
output.RenderOutput(output.Table{
r := output.RenderOutput(output.Table{
Header: tableHeader,
Data: data,
}, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
return nil
},
}
Expand Down Expand Up @@ -176,7 +178,7 @@ var configAddCmd = &cobra.Command{
if err := writeLagoonConfig(&lagoonCLIConfig, filepath.Join(configFilePath, configName+configExtension)); err != nil {
return fmt.Errorf("couldn't write config: %v", err)
}
output.RenderOutput(output.Table{
r := output.RenderOutput(output.Table{
Header: []string{
"Name",
"GraphQL",
Expand All @@ -198,6 +200,7 @@ var configAddCmd = &cobra.Command{
},
},
}, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
} else {
return fmt.Errorf("must have Hostname, Port, and GraphQL endpoint")
}
Expand Down
17 changes: 13 additions & 4 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"context"
"fmt"
"github.com/uselagoon/lagoon-cli/pkg/output"
"strconv"

lclient "github.com/uselagoon/machinery/api/lagoon/client"
Expand Down Expand Up @@ -80,7 +81,9 @@ use 'lagoon deploy latest' instead`,
if err != nil {
return err
}
fmt.Println(result.DeployEnvironmentBranch)
resultData := output.Result{Result: result.DeployEnvironmentBranch}
r := output.RenderResult(resultData, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
}
return nil
},
Expand Down Expand Up @@ -143,7 +146,9 @@ var deployPromoteCmd = &cobra.Command{
if err != nil {
return err
}
fmt.Println(result.DeployEnvironmentPromote)
resultData := output.Result{Result: result.DeployEnvironmentPromote}
r := output.RenderResult(resultData, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
}
return nil
},
Expand Down Expand Up @@ -204,7 +209,9 @@ This environment should already exist in lagoon. It is analogous with the 'Deplo
if err != nil {
return err
}
fmt.Println(result.DeployEnvironmentLatest)
resultData := output.Result{Result: result.DeployEnvironmentLatest}
r := output.RenderResult(resultData, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
}
return nil
},
Expand Down Expand Up @@ -291,7 +298,9 @@ This pullrequest may not already exist as an environment in lagoon.`,
if err != nil {
return err
}
fmt.Println(result.DeployEnvironmentPullrequest)
resultData := output.Result{Result: result.DeployEnvironmentPullrequest}
r := output.RenderResult(resultData, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
}
return nil
},
Expand Down
15 changes: 10 additions & 5 deletions cmd/deploytarget.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ var addDeployTargetCmd = &cobra.Command{
returnNonEmptyString(fmt.Sprintf("%v", addDeployTargetResponse.Created)),
returnNonEmptyString(fmt.Sprintf("%v", addDeployTargetResponse.MonitoringConfig)),
})
output.RenderOutput(output.Table{
r := output.RenderOutput(output.Table{
Header: []string{
"ID",
"Name",
Expand All @@ -138,6 +138,7 @@ var addDeployTargetCmd = &cobra.Command{
},
Data: data,
}, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
}
return nil
},
Expand Down Expand Up @@ -252,7 +253,7 @@ var updateDeployTargetCmd = &cobra.Command{
returnNonEmptyString(fmt.Sprintf("%v", updateDeployTargetResponse.Created)),
returnNonEmptyString(fmt.Sprintf("%v", updateDeployTargetResponse.MonitoringConfig)),
})
output.RenderOutput(output.Table{
r := output.RenderOutput(output.Table{
Header: []string{
"ID",
"Name",
Expand All @@ -270,6 +271,7 @@ var updateDeployTargetCmd = &cobra.Command{
},
Data: data,
}, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
}
return nil
},
Expand Down Expand Up @@ -319,7 +321,8 @@ var deleteDeployTargetCmd = &cobra.Command{
resultData := output.Result{
Result: deleteDeployTargetResponse.DeleteDeployTarget,
}
output.RenderResult(resultData, outputOptions)
r := output.RenderResult(resultData, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
}
return nil
},
Expand Down Expand Up @@ -383,7 +386,8 @@ var addDeployTargetToOrganizationCmd = &cobra.Command{
"Organization Name": deployTargetResponse.Name,
},
}
output.RenderResult(resultData, outputOptions)
r := output.RenderResult(resultData, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
return nil
},
}
Expand Down Expand Up @@ -447,7 +451,8 @@ var removeDeployTargetFromOrganizationCmd = &cobra.Command{
"Organization Name": organizationName,
},
}
output.RenderResult(resultData, outputOptions)
r := output.RenderResult(resultData, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
}
return nil
},
Expand Down
15 changes: 11 additions & 4 deletions cmd/deploytargetconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ var addDeployTargetConfigCmd = &cobra.Command{
returnNonEmptyString(fmt.Sprintf("%v", deployTargetConfig.DeployTarget.CloudProvider)),
returnNonEmptyString(fmt.Sprintf("%v", deployTargetConfig.DeployTarget.CloudRegion)),
})
output.RenderOutput(output.Table{
r := output.RenderOutput(output.Table{
Header: []string{
"ID",
"Weight",
Expand All @@ -103,6 +103,7 @@ var addDeployTargetConfigCmd = &cobra.Command{
},
Data: data,
}, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
}
return nil
},
Expand Down Expand Up @@ -184,7 +185,7 @@ var updateDeployTargetConfigCmd = &cobra.Command{
returnNonEmptyString(fmt.Sprintf("%v", deployTargetConfig.DeployTarget.CloudProvider)),
returnNonEmptyString(fmt.Sprintf("%v", deployTargetConfig.DeployTarget.CloudRegion)),
})
output.RenderOutput(output.Table{
r := output.RenderOutput(output.Table{
Header: []string{
"ID",
"Weight",
Expand All @@ -197,6 +198,7 @@ var updateDeployTargetConfigCmd = &cobra.Command{
},
Data: data,
}, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
}
return nil
},
Expand Down Expand Up @@ -247,7 +249,11 @@ var deleteDeployTargetConfigCmd = &cobra.Command{
if err != nil {
return err
}
fmt.Println(result.DeleteDeployTargetConfig)
resultData := output.Result{
Result: result.DeleteDeployTargetConfig,
}
r := output.RenderResult(resultData, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
}
return nil
},
Expand Down Expand Up @@ -306,7 +312,7 @@ var listDeployTargetConfigsCmd = &cobra.Command{
returnNonEmptyString(fmt.Sprintf("%v", deployTargetConfig.DeployTarget.CloudRegion)),
})
}
output.RenderOutput(output.Table{
r := output.RenderOutput(output.Table{
Header: []string{
"ID",
"Weight",
Expand All @@ -319,6 +325,7 @@ var listDeployTargetConfigsCmd = &cobra.Command{
},
Data: data,
}, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
return nil
},
}
Expand Down
13 changes: 9 additions & 4 deletions cmd/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ var deleteEnvCmd = &cobra.Command{
resultData := output.Result{
Result: environment.DeleteEnvironment,
}
output.RenderResult(resultData, outputOptions)
r := output.RenderResult(resultData, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
}
return nil
},
Expand Down Expand Up @@ -172,7 +173,8 @@ var updateEnvironmentCmd = &cobra.Command{
"Environment Name": result.Name,
},
}
output.RenderResult(resultData, outputOptions)
r := output.RenderResult(resultData, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
return nil
},
}
Expand Down Expand Up @@ -233,7 +235,7 @@ var listBackupsCmd = &cobra.Command{
returnNonEmptyString(fmt.Sprintf("%v", backup.Restore.Status)),
})
}
output.RenderOutput(output.Table{
r := output.RenderOutput(output.Table{
Header: []string{
"BackupID",
"Source",
Expand All @@ -243,6 +245,7 @@ var listBackupsCmd = &cobra.Command{
},
Data: data,
}, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
return nil
},
}
Expand Down Expand Up @@ -290,7 +293,9 @@ 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 != "" {
fmt.Println(backup.Restore.RestoreLocation)
resultData := output.Result{Result: backup.Restore.RestoreLocation}
r := output.RenderResult(resultData, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
return nil
}
status = backup.Restore.Status
Expand Down
24 changes: 16 additions & 8 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ var getProjectCmd = &cobra.Command{

if project.Name == "" {
outputOptions.Error = fmt.Sprintf("No details for project '%s'\n", cmdProjectName)
output.RenderOutput(output.Table{Data: []output.Data{[]string{}}}, outputOptions)
r := output.RenderOutput(output.Table{Data: []output.Data{[]string{}}}, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
return nil
}

Expand Down Expand Up @@ -126,7 +127,8 @@ var getProjectCmd = &cobra.Command{
Header: projHeader,
Data: data,
}
output.RenderOutput(dataMain, outputOptions)
r := output.RenderOutput(dataMain, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
return nil
},
}
Expand Down Expand Up @@ -177,7 +179,8 @@ This returns information about a deployment, the logs of this build can also be
},
},
}
output.RenderOutput(dataMain, outputOptions)
r := output.RenderOutput(dataMain, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
return nil
}
dataMain := output.Table{
Expand All @@ -202,7 +205,8 @@ This returns information about a deployment, the logs of this build can also be
},
},
}
output.RenderOutput(dataMain, outputOptions)
r := output.RenderOutput(dataMain, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
return nil
},
}
Expand Down Expand Up @@ -278,7 +282,8 @@ var getEnvironmentCmd = &cobra.Command{
Header: envHeader,
Data: data,
}
output.RenderOutput(dataMain, outputOptions)
r := output.RenderOutput(dataMain, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
return nil
},
}
Expand Down Expand Up @@ -328,14 +333,16 @@ var getProjectKeyCmd = &cobra.Command{

if len(dataMain.Data) == 0 {
outputOptions.Error = fmt.Sprintf("No project-key for project '%s'", cmdProjectName)
output.RenderOutput(output.Table{Data: []output.Data{[]string{}}}, outputOptions)
r := output.RenderOutput(output.Table{Data: []output.Data{[]string{}}}, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
return nil
}

if projectKey.PrivateKey != "" {
dataMain.Header = append(dataMain.Header, "PrivateKey")
}
output.RenderOutput(dataMain, outputOptions)
r := output.RenderOutput(dataMain, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
return nil
},
}
Expand Down Expand Up @@ -405,7 +412,8 @@ var getOrganizationCmd = &cobra.Command{
Data: data,
}

output.RenderOutput(dataMain, outputOptions)
r := output.RenderOutput(dataMain, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
return nil
},
}
Expand Down
Loading

0 comments on commit 33d7950

Please sign in to comment.