refactor(print-env): remove redundant Output() wrapper method
Signed-off-by: Dominik Schmidt <dev@dominik-schmidt.de>
This commit is contained in:
parent
eb104ce5c8
commit
a082b7d4cc
|
|
@ -31,7 +31,7 @@ func NewPrintEnvCmd(globalCfg *config.GlobalImpl) *cobra.Command {
|
|||
}
|
||||
|
||||
f := cmd.Flags()
|
||||
f.StringVar(&printEnvOptions.Output, "output", "yaml", "output format: yaml or json")
|
||||
f.StringVar(&printEnvOptions.OutputFormat, "output", "yaml", "output format: yaml or json")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,17 +4,22 @@ import "fmt"
|
|||
|
||||
// PrintEnvOptions is the options for the print-env command
|
||||
type PrintEnvOptions struct {
|
||||
// Output is the output format (yaml or json)
|
||||
Output string
|
||||
// OutputFormat is the output format (yaml or json)
|
||||
OutputFormat string
|
||||
}
|
||||
|
||||
// NewPrintEnvOptions creates a new PrintEnvOptions
|
||||
func NewPrintEnvOptions() *PrintEnvOptions {
|
||||
return &PrintEnvOptions{
|
||||
Output: "yaml", // default to yaml
|
||||
OutputFormat: "yaml", // default to yaml
|
||||
}
|
||||
}
|
||||
|
||||
// Output returns the output format
|
||||
func (p *PrintEnvOptions) Output() string {
|
||||
return p.OutputFormat
|
||||
}
|
||||
|
||||
// PrintEnvImpl is impl for PrintEnvOptions
|
||||
type PrintEnvImpl struct {
|
||||
*GlobalImpl
|
||||
|
|
@ -29,15 +34,10 @@ func NewPrintEnvImpl(g *GlobalImpl, p *PrintEnvOptions) *PrintEnvImpl {
|
|||
}
|
||||
}
|
||||
|
||||
// Output returns the output format
|
||||
func (c *PrintEnvImpl) Output() string {
|
||||
return c.PrintEnvOptions.Output
|
||||
}
|
||||
|
||||
// ValidateConfig validates the print-env configuration
|
||||
func (c *PrintEnvImpl) ValidateConfig() error {
|
||||
if c.PrintEnvOptions.Output != "yaml" && c.PrintEnvOptions.Output != "json" {
|
||||
return fmt.Errorf("invalid output format %q: must be 'yaml' or 'json'", c.PrintEnvOptions.Output)
|
||||
if c.OutputFormat != "yaml" && c.OutputFormat != "json" {
|
||||
return fmt.Errorf("invalid output format %q: must be 'yaml' or 'json'", c.OutputFormat)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue