Skip to content

Commit

Permalink
refactor: output package return string
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon committed Aug 5, 2024
1 parent 8dea96d commit 36c1fd7
Show file tree
Hide file tree
Showing 19 changed files with 263 additions and 139 deletions.
6 changes: 4 additions & 2 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,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 +177,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 +199,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
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
9 changes: 6 additions & 3 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 @@ -306,7 +308,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 +321,7 @@ var listDeployTargetConfigsCmd = &cobra.Command{
},
Data: data,
}, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
return nil
},
}
Expand Down
9 changes: 6 additions & 3 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
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
18 changes: 12 additions & 6 deletions cmd/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ var addGroupCmd = &cobra.Command{
if organizationName != "" {
resultData.ResultData["Organization"] = organizationName
}
output.RenderResult(resultData, outputOptions)
r := output.RenderResult(resultData, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
return nil
},
}
Expand Down Expand Up @@ -162,7 +163,8 @@ var addUserToGroupCmd = &cobra.Command{
resultData := output.Result{
Result: "success",
}
output.RenderResult(resultData, outputOptions)
r := output.RenderResult(resultData, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
return nil
},
}
Expand Down Expand Up @@ -224,7 +226,8 @@ var addProjectToGroupCmd = &cobra.Command{
resultData := output.Result{
Result: "success",
}
output.RenderResult(resultData, outputOptions)
r := output.RenderResult(resultData, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
return nil
},
}
Expand Down Expand Up @@ -280,7 +283,8 @@ var deleteUserFromGroupCmd = &cobra.Command{
"id": result.ID,
},
}
output.RenderResult(resultData, outputOptions)
r := output.RenderResult(resultData, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
}
return nil
},
Expand Down Expand Up @@ -345,7 +349,8 @@ var deleteProjectFromGroupCmd = &cobra.Command{
resultData := output.Result{
Result: "success",
}
output.RenderResult(resultData, outputOptions)
r := output.RenderResult(resultData, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
}
return nil
},
Expand Down Expand Up @@ -384,7 +389,8 @@ var deleteGroupCmd = &cobra.Command{
resultData := output.Result{
Result: "success",
}
output.RenderResult(resultData, outputOptions)
r := output.RenderResult(resultData, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
}
return nil
},
Expand Down
Loading

0 comments on commit 36c1fd7

Please sign in to comment.