diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-05-27 15:04:36 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-05-27 16:56:54 +0200 |
commit | f86b5f70a60fc3793bc826f2ccd8dcdd62e26b51 (patch) | |
tree | 05cc4ed0e7856dc114787c98689853d195bc291d /commands/config.go | |
parent | 3297b395d8d5fadb45b9055e55458967fb9f4a76 (diff) |
commands: Move the --format flag to only the commands that support it
Fixes #11022
Diffstat (limited to 'commands/config.go')
-rw-r--r-- | commands/config.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/commands/config.go b/commands/config.go index ce3ad04fa..5cbcdff2a 100644 --- a/commands/config.go +++ b/commands/config.go @@ -17,6 +17,7 @@ import ( "bytes" "context" "encoding/json" + "fmt" "os" "strings" "time" @@ -40,6 +41,8 @@ func newConfigCommand() *configCommand { type configCommand struct { r *rootCommand + format string + commands []simplecobra.Commander } @@ -67,7 +70,7 @@ func (c *configCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, arg return err } - format := strings.ToLower(c.r.format) + format := strings.ToLower(c.format) switch format { case "json": @@ -83,6 +86,8 @@ func (c *configCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, arg return parser.InterfaceToConfig(m, metadecoders.YAML, os.Stdout) case "toml": return parser.InterfaceToConfig(m, metadecoders.TOML, os.Stdout) + default: + return fmt.Errorf("unsupported format: %q", format) } } @@ -93,6 +98,8 @@ func (c *configCommand) Init(cd *simplecobra.Commandeer) error { cmd := cd.CobraCommand cmd.Short = "Print the site configuration" cmd.Long = `Print the site configuration, both default and custom settings.` + cmd.Flags().StringVar(&c.format, "format", "toml", "preferred file format (toml, yaml or json)") + return nil } |