-
Notifications
You must be signed in to change notification settings - Fork 6
/
printer.go
83 lines (70 loc) · 2.35 KB
/
printer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package nodepools
import (
"fmt"
"github.com/giantswarm/microerror"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/cli-runtime/pkg/printers"
"github.com/giantswarm/kubectl-gs/v3/cmd/get/nodepools/provider"
"github.com/giantswarm/kubectl-gs/v3/internal/feature"
"github.com/giantswarm/kubectl-gs/v3/internal/key"
"github.com/giantswarm/kubectl-gs/v3/pkg/data/domain/nodepool"
"github.com/giantswarm/kubectl-gs/v3/pkg/output"
)
type PrintOptions struct {
Name string
}
func (r *runner) printOutput(npResource nodepool.Resource) error {
var err error
var printer printers.ResourcePrinter
var resource runtime.Object
switch {
case output.IsOutputDefault(r.flag.print.OutputFormat):
switch r.provider {
case key.ProviderAWS:
capabilities := feature.New(feature.ProviderAWS)
resource = provider.GetAWSTable(npResource, capabilities)
case key.ProviderCAPA:
capabilities := feature.New(feature.ProviderCAPA)
resource = provider.GetCAPATable(npResource, capabilities)
case key.ProviderCAPZ:
capabilities := feature.New(feature.ProviderCAPZ)
resource = provider.GetCAPITable(npResource, capabilities)
case key.ProviderAzure:
capabilities := feature.New(feature.ProviderAzure)
resource = provider.GetAzureTable(npResource, capabilities)
case key.ProviderCloudDirector:
capabilities := feature.New(feature.ProviderCloudDirector)
resource = provider.GetCAPITable(npResource, capabilities)
case key.ProviderVSphere:
capabilities := feature.New(feature.ProviderVSphere)
resource = provider.GetCAPITable(npResource, capabilities)
}
printOptions := printers.PrintOptions{
WithNamespace: r.flag.AllNamespaces,
}
printer = printers.NewTablePrinter(printOptions)
case output.IsOutputName(r.flag.print.OutputFormat):
resource = npResource.Object()
err = output.PrintResourceNames(r.stdout, resource)
if err != nil {
return microerror.Mask(err)
}
return nil
default:
resource = npResource.Object()
printer, err = r.flag.print.ToPrinter()
if err != nil {
return microerror.Mask(err)
}
}
err = printer.PrintObj(resource, r.stdout)
if err != nil {
return microerror.Mask(err)
}
return nil
}
func (r *runner) printNoResourcesOutput() {
fmt.Fprintf(r.stdout, "No node pools found.\n")
fmt.Fprintf(r.stdout, "To create a node pool, please check\n\n")
fmt.Fprintf(r.stdout, " kubectl gs template nodepool --help\n")
}