Skip to content

Commit

Permalink
Use printers from genericcli except for table printer. (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 authored Jun 11, 2024
1 parent 6ffb1cd commit a0d8b95
Show file tree
Hide file tree
Showing 16 changed files with 176 additions and 206 deletions.
5 changes: 2 additions & 3 deletions cmd/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/fi-ts/cloud-go/api/client/audit"
"github.com/fi-ts/cloud-go/api/models"
"github.com/fi-ts/cloudctl/cmd/output"
"github.com/go-openapi/strfmt"
"github.com/metal-stack/metal-lib/pkg/genericcli"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -106,7 +105,7 @@ func (c *config) auditList() error {
return err
}

return output.New().Print(resp.Payload)
return c.listPrinter.Print(resp.Payload)
}

func (c *config) auditDescribe(args []string) error {
Expand Down Expand Up @@ -139,7 +138,7 @@ func (c *config) auditDescribe(args []string) error {
}
}

return output.New().Print(trace)
return c.describePrinter.Print(trace)
}

func eventuallyRelativeDateTime(s string) (strfmt.DateTime, error) {
Expand Down
21 changes: 10 additions & 11 deletions cmd/billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/fi-ts/cloud-go/api/client/accounting"
"github.com/fi-ts/cloud-go/api/models"
"github.com/fi-ts/cloudctl/cmd/output"
"github.com/go-openapi/strfmt"
"github.com/go-playground/validator/v10"
"github.com/jinzhu/now"
Expand Down Expand Up @@ -413,7 +412,7 @@ func (c *config) projectsBilling() error {
return err
}

return output.New().Print(response.Payload)
return c.listPrinter.Print(response.Payload)
}

func (c *config) clusterUsage() error {
Expand Down Expand Up @@ -447,7 +446,7 @@ func (c *config) clusterUsageJSON(cur *models.V1ClusterUsageRequest) error {
return err
}

return output.New().Print(response.Payload)
return c.listPrinter.Print(response.Payload)
}

func (c *config) clusterUsageCSV(cur *models.V1ClusterUsageRequest) error {
Expand Down Expand Up @@ -493,7 +492,7 @@ func (c *config) machineUsage() error {
return err
}

return output.New().Print(response.Payload)
return c.listPrinter.Print(response.Payload)
}

func (c *config) productOptionUsage() error {
Expand All @@ -520,7 +519,7 @@ func (c *config) productOptionUsage() error {
return err
}

return output.New().Print(response.Payload)
return c.listPrinter.Print(response.Payload)
}

func (c *config) containerUsage() error {
Expand Down Expand Up @@ -560,7 +559,7 @@ func (c *config) containerUsageJSON(cur *models.V1ContainerUsageRequest) error {
return err
}

return output.New().Print(response.Payload)
return c.listPrinter.Print(response.Payload)
}

func (c *config) containerUsageCSV(cur *models.V1ContainerUsageRequest) error {
Expand Down Expand Up @@ -607,7 +606,7 @@ func (c *config) ipUsageJSON(iur *models.V1IPUsageRequest) error {
return err
}

return output.New().Print(response.Payload)
return c.listPrinter.Print(response.Payload)
}

func (c *config) ipUsageCSV(iur *models.V1IPUsageRequest) error {
Expand Down Expand Up @@ -657,7 +656,7 @@ func (c *config) networkTrafficUsageJSON(cur *models.V1NetworkUsageRequest) erro
return err
}

return output.New().Print(response.Payload)
return c.listPrinter.Print(response.Payload)
}

func (c *config) networkTrafficUsageCSV(cur *models.V1NetworkUsageRequest) error {
Expand Down Expand Up @@ -701,7 +700,7 @@ func (c *config) s3UsageJSON(sur *models.V1S3UsageRequest) error {
return err
}

return output.New().Print(response.Payload)
return c.listPrinter.Print(response.Payload)
}

func (c *config) s3UsageCSV(sur *models.V1S3UsageRequest) error {
Expand Down Expand Up @@ -754,7 +753,7 @@ func (c *config) volumeUsageJSON(vur *models.V1VolumeUsageRequest) error {
return err
}

return output.New().Print(response.Payload)
return c.listPrinter.Print(response.Payload)
}

func (c *config) volumeUsageCSV(vur *models.V1VolumeUsageRequest) error {
Expand Down Expand Up @@ -807,7 +806,7 @@ func (c *config) postgresUsageJSON(cur *models.V1PostgresUsageRequest) error {
return err
}

return output.New().Print(response.Payload)
return c.listPrinter.Print(response.Payload)
}

func (c *config) postgresUsageCSV(cur *models.V1PostgresUsageRequest) error {
Expand Down
50 changes: 25 additions & 25 deletions cmd/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ WARNING: You are going to create a cluster that has no default internet access w
if err != nil {
return err
}
return output.New().Print(shoot.Payload)
return c.describePrinter.Print(shoot.Payload)
}

func (c *config) clusterList() error {
Expand Down Expand Up @@ -775,15 +775,15 @@ func (c *config) clusterList() error {
if err != nil {
return err
}
return output.New().Print(response.Payload)
return c.listPrinter.Print(response.Payload)
}

request := cluster.NewListClustersParams()
shoots, err := c.cloud.Cluster.ListClusters(request, nil)
if err != nil {
return err
}
return output.New().Print(shoots.Payload)
return c.listPrinter.Print(shoots.Payload)
}

func (c *config) clusterKubeconfig(args []string) error {
Expand Down Expand Up @@ -896,7 +896,7 @@ func (c *config) reconcileCluster(args []string) error {
if err != nil {
return err
}
return output.New().Print(shoot.Payload)
return c.describePrinter.Print(shoot.Payload)
}

func (c *config) updateCluster(args []string) error {
Expand Down Expand Up @@ -1341,7 +1341,7 @@ func (c *config) updateCluster(args []string) error {
if err != nil {
return err
}
return output.New().Print(shoot.Payload)
return c.describePrinter.Print(shoot.Payload)
}

func (c *config) clusterDelete(args []string) error {
Expand All @@ -1360,7 +1360,7 @@ func (c *config) clusterDelete(args []string) error {
return err
}

genericcli.Must(output.New().Print(resp.Payload))
genericcli.Must(c.listPrinter.Print(resp.Payload))

firstPartOfClusterID := strings.Split(*resp.Payload.ID, "-")[0]
fmt.Println("Please answer some security questions to delete this cluster")
Expand All @@ -1379,7 +1379,7 @@ func (c *config) clusterDelete(args []string) error {
if err != nil {
return err
}
return output.New().Print(cl.Payload)
return c.describePrinter.Print(cl.Payload)
}

func (c *config) clusterDescribe(args []string) error {
Expand All @@ -1396,7 +1396,7 @@ func (c *config) clusterDescribe(args []string) error {
if err != nil {
return err
}
return output.New().Print(shoot.Payload)
return c.describePrinter.Print(shoot.Payload)
}

func (c *config) clusterIssues(args []string) error {
Expand Down Expand Up @@ -1435,15 +1435,15 @@ func (c *config) clusterIssues(args []string) error {
if err != nil {
return err
}
return output.New().Print(output.ShootIssuesResponses(response.Payload))
return c.listPrinter.Print(output.ShootIssuesResponses(response.Payload))
}

request := cluster.NewListClustersParams().WithReturnMachines(&boolTrue)
shoots, err := c.cloud.Cluster.ListClusters(request, nil)
if err != nil {
return err
}
return output.New().Print(output.ShootIssuesResponses(shoots.Payload))
return c.listPrinter.Print(output.ShootIssuesResponses(shoots.Payload))
}

ci, err := c.clusterID("issues", args)
Expand All @@ -1456,7 +1456,7 @@ func (c *config) clusterIssues(args []string) error {
if err != nil {
return err
}
return output.New().Print(output.ShootIssuesResponse(shoot.Payload))
return c.listPrinter.Print(output.ShootIssuesResponse(shoot.Payload))
}

func (c *config) clusterMachines(args []string) error {
Expand All @@ -1471,17 +1471,17 @@ func (c *config) clusterMachines(args []string) error {
return err
}

if output.New().Type() != "table" {
return output.New().Print(shoot.Payload)
if viper.GetString("output-format") != "table" {
return c.describePrinter.Print(shoot.Payload)
}

fmt.Println("Cluster:")
genericcli.Must(output.New().Print(shoot.Payload))
genericcli.Must(c.listPrinter.Print(shoot.Payload))

ms := shoot.Payload.Machines
ms = append(ms, shoot.Payload.Firewalls...)
fmt.Println("\nMachines:")
return output.New().Print(ms)
return c.listPrinter.Print(ms)
}

func (c *config) clusterLogs(args []string) error {
Expand All @@ -1504,33 +1504,33 @@ func (c *config) clusterLogs(args []string) error {
lastErrors = shoot.Payload.Status.LastErrors
}

if output.New().Type() != "table" {
if viper.GetString("output-format") != "table" {
type s struct {
Conditions []*models.V1beta1Condition
LastOperation *models.V1beta1LastOperation
LastErrors []*models.V1beta1LastError
}
return output.New().Print(s{
return c.describePrinter.Print(s{
Conditions: conditions,
LastOperation: lastOperation,
LastErrors: lastErrors,
})
}

fmt.Println("Conditions:")
err = output.New().Print(conditions)
err = c.listPrinter.Print(conditions)
if err != nil {
return err
}

fmt.Println("\nLast Errors:")
err = output.New().Print(lastErrors)
err = c.listPrinter.Print(lastErrors)
if err != nil {
return err
}

fmt.Println("\nLast Operation:")
return output.New().Print(lastOperation)
return c.listPrinter.Print(lastOperation)
}

func (c *config) clusterInputs() error {
Expand All @@ -1544,7 +1544,7 @@ func (c *config) clusterInputs() error {
return err
}

return output.New().Print(sc)
return c.describePrinter.Print(sc.Payload)
}

func (c *config) clusterDNSManifest(args []string) error {
Expand Down Expand Up @@ -1688,7 +1688,7 @@ func (c *config) clusterMachineReset(args []string) error {
ms := shoot.Payload.Machines
ms = append(ms, shoot.Payload.Firewalls...)

return output.New().Print(ms)
return c.listPrinter.Print(ms)
}

func (c *config) clusterMachineCycle(args []string) error {
Expand All @@ -1710,7 +1710,7 @@ func (c *config) clusterMachineCycle(args []string) error {
ms := shoot.Payload.Machines
ms = append(ms, shoot.Payload.Firewalls...)

return output.New().Print(ms)
return c.listPrinter.Print(ms)
}

func (c *config) clusterMachineReinstall(args []string) error {
Expand All @@ -1736,7 +1736,7 @@ func (c *config) clusterMachineReinstall(args []string) error {
ms := shoot.Payload.Machines
ms = append(ms, shoot.Payload.Firewalls...)

return output.New().Print(ms)
return c.listPrinter.Print(ms)
}

func (c *config) clusterMachinePackages(args []string) error {
Expand Down Expand Up @@ -1800,7 +1800,7 @@ func (c *config) clusterMonitoringSecret(args []string) error {
return err
}

return output.New().Print(secret.Payload)
return c.describePrinter.Print(secret.Payload)
}

func (c *config) clusterMachineSSH(args []string, console bool) error {
Expand Down
3 changes: 1 addition & 2 deletions cmd/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"

"github.com/fatih/color"
"github.com/fi-ts/cloudctl/cmd/output"
"github.com/fi-ts/cloudctl/pkg/api"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -111,5 +110,5 @@ func (c *config) contextList() error {
if err != nil {
return err
}
return output.New().Print(ctxs)
return c.listPrinter.Print(ctxs)
}
5 changes: 2 additions & 3 deletions cmd/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"

"github.com/fi-ts/cloud-go/api/client/health"
"github.com/fi-ts/cloudctl/cmd/output"
"github.com/metal-stack/metal-lib/pkg/genericcli"
"github.com/spf13/cobra"
)
Expand All @@ -26,11 +25,11 @@ func newHealthCmd(c *config) *cobra.Command {
}
}

genericcli.Must(output.New().Print(resp.Payload))
genericcli.Must(c.listPrinter.Print(resp.Payload))

fmt.Println()

return output.New().Print(resp.Payload.Services)
return c.listPrinter.Print(resp.Payload.Services)
},
}
return healthCmd
Expand Down
Loading

0 comments on commit a0d8b95

Please sign in to comment.