-
Notifications
You must be signed in to change notification settings - Fork 18
/
view.go
63 lines (50 loc) · 1.34 KB
/
view.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
/*
SPDX-FileCopyrightText: 2021 SAP SE or an SAP affiliate company and Gardener contributors
SPDX-License-Identifier: Apache-2.0
*/
package config
import (
"github.com/spf13/cobra"
"github.com/gardener/gardenctl-v2/internal/util"
"github.com/gardener/gardenctl-v2/pkg/cmd/base"
"github.com/gardener/gardenctl-v2/pkg/config"
)
// NewCmdConfigView returns a new (config) view command.
func NewCmdConfigView(f util.Factory, ioStreams util.IOStreams) *cobra.Command {
o := &viewOptions{
Options: base.Options{
IOStreams: ioStreams,
},
}
cmd := &cobra.Command{
Use: "view",
Short: "Print the gardenctl configuration",
Example: `# view current configuration
gardenctl config view`,
RunE: base.WrapRunE(o, f),
}
o.AddFlags(cmd.Flags())
o.RegisterCompletionsForOutputFlag(cmd)
return cmd
}
type viewOptions struct {
base.Options
// Configuration is the gardenctl configuration
Configuration *config.Config
}
// Complete adapts from the command line args to the data required.
func (o *viewOptions) Complete(f util.Factory, _ *cobra.Command, _ []string) error {
config, err := getConfiguration(f)
if err != nil {
return err
}
o.Configuration = config
if o.Output == "" {
o.Output = "yaml"
}
return nil
}
// Run executes the command.
func (o *viewOptions) Run(_ util.Factory) error {
return o.PrintObject(o.Configuration)
}