Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd: initialize config fields before use #100

Merged
merged 1 commit into from Mar 29, 2023

Conversation

badouralix
Copy link
Contributor

Fixes #99 by introducing config constructors
Note that this is one way to fix the issue, alternatives can be considered too

Without any .yamlfmt, yamlfmt behaves as expected, here below with debug logs :

$ rm .yamlfmt

$ go run ./cmd/yamlfmt
{Extensions:[yaml yml] Include:[] Exclude:[] Doublestar:false LineEnding:lf FormatterConfig:0x14000120168}
{Type: FormatterSettings:map[]}

$ go run ./cmd/yamlfmt --formatter retain_line_breaks=true
{Extensions:[yaml yml] Include:[] Exclude:[] Doublestar:false LineEnding:lf FormatterConfig:0x14000118150}
{Type: FormatterSettings:map[retain_line_breaks:true]}

Same expected behavior when .yamlfmt contains no overrides :

$ cat .yamlfmt
formatter:
  type: basic

$ go run ./cmd/yamlfmt
{Extensions:[yaml yml] Include:[] Exclude:[] Doublestar:false LineEnding:lf FormatterConfig:0x14000124168}
{Type:basic FormatterSettings:map[]}

$ go run ./cmd/yamlfmt --formatter retain_line_breaks=true
{Extensions:[yaml yml] Include:[] Exclude:[] Doublestar:false LineEnding:lf FormatterConfig:0x1400000c180}
{Type:basic FormatterSettings:map[retain_line_breaks:true]}

Same expected behavior when .yamlfmt contains at least one overrides :

$ cat .yamlfmt
formatter:
  type: basic
  retain_line_breaks: false

$ go run ./cmd/yamlfmt
{Extensions:[yaml yml] Include:[] Exclude:[] Doublestar:false LineEnding:lf FormatterConfig:0x14000114168}
{Type:basic FormatterSettings:map[retain_line_breaks:false]}

$ go run ./cmd/yamlfmt --formatter retain_line_breaks=true
{Extensions:[yaml yml] Include:[] Exclude:[] Doublestar:false LineEnding:lf FormatterConfig:0x140000a0168}
{Type:basic FormatterSettings:map[retain_line_breaks:true]}

Signed-off-by: Ayaz Badouraly <ayaz.badouraly@datadoghq.com>
Copy link
Collaborator

@braydonk braydonk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason I thought mapstructure would just decode to an empty map instead of nil so I neglected to try this use case. Thank you very much for the fix!

@braydonk braydonk merged commit 7f8bfab into google:main Mar 29, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic on formatter options through cli args
2 participants