-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Empty get addons
returns empty json/yaml array instead of empty string
#4922
Conversation
f247e24
to
aa9c508
Compare
pkg/ctl/get/addon.go
Outdated
@@ -92,8 +92,15 @@ func getAddon(cmd *cmdutils.Cmd, params *getCmdParams) error { | |||
|
|||
if len(summaries) == 0 { | |||
logger.Info("no addons found") | |||
return nil | |||
if params.output == "json" || params.output == "yaml" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this whole logic should be shifted into the printer. This has the added problem that any kind of additional change will affect this little logic differently. If we wrap the output into something we'll have to remember to update this. Just shift the whole decision into the printer and then call the printer. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I've moved the logic into the printers.
I didn't find a simple way not to repeat the code.
Also, I create a string empty slice, as we know it's empty anyway.
And I've also fixed maps, after checking they're facing the same bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try to add some printer tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some tests and updated the PR description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gdlx Thank you for doing this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm! nice job, well done for figuring out a nice way to do this. :)
e6fd330
to
a1064f4
Compare
get addons
returns empty json/yaml array instead of empty string
Description
Returns empty json/yaml array/map instead of an empty strings when sending empty slice/array/map to Json/Yaml printers.
I had to call
make
to avoidMarshall
to returnnull
. I turned empty objects into string array/map as they're empty anyway.Fixes #4910
Checklist
README.md
, or theuserdocs
directory)area/nodegroup
) and kind (e.g.kind/improvement
)BONUS POINTS checklist: complete for good vibes and maybe prizes?! 🤯