Skip to content

Commit

Permalink
commands: Add --printZero to the config command
Browse files Browse the repository at this point in the history
Will include zero config values (e.g. "", 0, false) in the output and will be more verbose, but useful if you cant to discover all available config options.
  • Loading branch information
bep committed Jan 15, 2025
1 parent 7699336 commit 5bb1564
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions commands/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ func newConfigCommand() *configCommand {
type configCommand struct {
r *rootCommand

format string
lang string
format string
lang string
printZero bool

commands []simplecobra.Commander
}
Expand Down Expand Up @@ -78,7 +79,7 @@ func (c *configCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, arg
dec.SetIndent("", " ")
dec.SetEscapeHTML(false)

if err := dec.Encode(parser.ReplacingJSONMarshaller{Value: config, KeysToLower: true, OmitEmpty: true}); err != nil {
if err := dec.Encode(parser.ReplacingJSONMarshaller{Value: config, KeysToLower: true, OmitEmpty: !c.printZero}); err != nil {
return err
}

Expand Down Expand Up @@ -115,6 +116,7 @@ func (c *configCommand) Init(cd *simplecobra.Commandeer) error {
cmd.Flags().StringVar(&c.format, "format", "toml", "preferred file format (toml, yaml or json)")
_ = cmd.RegisterFlagCompletionFunc("format", cobra.FixedCompletions([]string{"toml", "yaml", "json"}, cobra.ShellCompDirectiveNoFileComp))
cmd.Flags().StringVar(&c.lang, "lang", "", "the language to display config for. Defaults to the first language defined.")
cmd.Flags().BoolVar(&c.printZero, "printZero", false, `include config options with zero values (e.g. false, 0, "") in the output`)
_ = cmd.RegisterFlagCompletionFunc("lang", cobra.NoFileCompletions)
applyLocalFlagsBuildConfig(cmd, c.r)

Expand Down

0 comments on commit 5bb1564

Please sign in to comment.