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

Add CSV output option #279

Merged
merged 8 commits into from
Feb 25, 2022
Merged

Add CSV output option #279

merged 8 commits into from
Feb 25, 2022

Conversation

mikejoh
Copy link
Contributor

@mikejoh mikejoh commented Feb 23, 2022

This PR fixes #278

Checklist

  • I have signed the CLA
  • I have updated/added any relevant documentation

Description

What's the goal of this PR?

The goal of this PR is to add another output option via the --output flag to be able to output CSV formatted data.

What changes did you make?

I added an extra output option called csv which will, if used, output data to stdout in CSV format.

What alternative solution should we consider, if any?

N/A

* Rename variables to something more descriptive
* Return a *csv.Writer from csvOut() and call writer.Flush() from the DisplayOutput method instead
* Check for csv.Writer errors
@lucasreed
Copy link
Contributor

Hey @mikejoh thanks for the PR! At first glance this looks great, thanks for adding tests. We'll take a closer look asap.

var row []string
for _, k := range columnIndexes {
if columns[k].value(o) == "" {
row = append(row, "n/a")
Copy link
Contributor Author

@mikejoh mikejoh Feb 23, 2022

Choose a reason for hiding this comment

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

This might be uncalled for when thinking about it, during testing I noticed that I got an extra trailing , in the end of rows (last column) where there are no data (empty string). I then added something to replace that with, in this case a n/a, to fill in the blanks basically.

I don't think that the trailing , is a problem but adding n/a might be something users won't expect since there are no other output options that add this to the output of data. This would also add a n/a at any place where there is an empty string.

WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you're right that a trailing comma is normal in a csv file and in fact ok if there are empty columns with a few commas in a row having nothing between them. We can remove that n/a as you suggest.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great! Fixed in: 64edde6

Copy link
Contributor

@lucasreed lucasreed left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks again.

@lucasreed lucasreed self-requested a review February 23, 2022 20:03
Copy link
Contributor

@lucasreed lucasreed left a comment

Choose a reason for hiding this comment

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

Changing my review for the n/a change is made to the output.

@lucasreed lucasreed self-requested a review February 25, 2022 15:18
@lucasreed lucasreed merged commit 718376b into FairwindsOps:master Feb 25, 2022
@mikejoh mikejoh deleted the csv-output branch February 25, 2022 18:50
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.

Output data in CSV format
2 participants