Skip to content

Commit 5bb1564

Browse files
committed
commands: Add --printZero to the config command
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.
1 parent 7699336 commit 5bb1564

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

commands/config.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ func newConfigCommand() *configCommand {
4343
type configCommand struct {
4444
r *rootCommand
4545

46-
format string
47-
lang string
46+
format string
47+
lang string
48+
printZero bool
4849

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

81-
if err := dec.Encode(parser.ReplacingJSONMarshaller{Value: config, KeysToLower: true, OmitEmpty: true}); err != nil {
82+
if err := dec.Encode(parser.ReplacingJSONMarshaller{Value: config, KeysToLower: true, OmitEmpty: !c.printZero}); err != nil {
8283
return err
8384
}
8485

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

0 commit comments

Comments
 (0)