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

feat: Add util functions to create tables from slices of structs #217

Merged
merged 7 commits into from Jun 6, 2021

Conversation

tw1nk
Copy link
Contributor

@tw1nk tw1nk commented Jun 2, 2021

Description

Describe your work here.

This makes it easy to print a slice of structs. or a slice of pointers to structs

Scope

What is affected by this pull request?

  • Bug Fix
  • New Feature
  • Documentation
  • Other

Related Issue

Fixes #

To-Do Checklist

  • I tested my changes
  • I have commented every method that I created/changed
  • I updated the examples to fit with my changes
  • I have added tests for my newly created methods

This makes it easy to print a slice of structs. or a slice of pointers
to structs
@tw1nk tw1nk requested a review from MarvinJWendt as a code owner June 2, 2021 23:15
@codecov
Copy link

codecov bot commented Jun 3, 2021

Codecov Report

Merging #217 (021a66b) into master (419a281) will not change coverage.
The diff coverage is n/a.

❗ Current head 021a66b differs from pull request most recent head 5bd3778. Consider uploading reports for the commit 5bd3778 to get more accurate results
Impacted file tree graph

@@            Coverage Diff            @@
##            master      #217   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           24        24           
  Lines         1243      1243           
=========================================
  Hits          1243      1243           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 419a281...5bd3778. Read the comment docs.

@tw1nk tw1nk changed the title Add WithSliceOfStruct to the table printer feat: Add WithSliceOfStruct to the table printer Jun 3, 2021
@MarvinJWendt
Copy link
Member

MarvinJWendt commented Jun 3, 2021

Hi @tw1nk, thanks for the PR! I really like the feature. For such features, we have a dedicated package named putils. It contains utility function for PTerm, and we planned to include some methods for automatically filling tables via different input types (which your feature does). So if you could refactor your changes into the putils package (it's in the root of this repo) that would be awesome! Just create a new go file and name it table-from-struct-slice, which contains two methods:

TableFromStructSlice(tablePrinter, structSlice) pterm.TablePrinter // Accepts a customized table printer and adds data to it, then returns it.
DefaultTableFromStructSlice(tablePrinter, structSlice) pterm.TablePrinter // Uses the first method and feeds the default table printer into the first param and returns the table filled with your computed data.

Another quick note: You're committing from an email address which seems to be disconnected from your GitHub account. So those commits won't appear on your GitHub profile, and you won't be listed in our "Contributors" section. You can simply add your commit email to your GitHub account to link the commits, but you don't have to. :)

@MarvinJWendt MarvinJWendt added needs refactor Something that needs to be refactored. proposal-accepted Proposals which are accepted for implementation in the future labels Jun 3, 2021
@tw1nk
Copy link
Contributor Author

tw1nk commented Jun 3, 2021

Thanks will do. You already had a utility method WithCSVReader which was why I added it to the normal table printer.

Regarding the email. thanks, i'll do that :D working from home and haven't setup my normal account on the work computer yet.

@tw1nk tw1nk changed the title feat: Add WithSliceOfStruct to the table printer feat: Add util functions to create tables from slices of structs Jun 3, 2021
@MarvinJWendt
Copy link
Member

MarvinJWendt commented Jun 4, 2021

Hi @tw1nk, I have refactored the PR a little, and tested it. I would merge it, but could you please change the filename real quick? It has a typo in "from". I will merge it then :)
Thanks for contributing 🚀

And you don't need to update the putils readme, it will update itself, once it hits our CI-System 😉

@MarvinJWendt MarvinJWendt enabled auto-merge (squash) June 6, 2021 14:57
Copy link
Member

@MarvinJWendt MarvinJWendt left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for contributing :)

@MarvinJWendt MarvinJWendt merged commit c47acdd into pterm:master Jun 6, 2021
@MarvinJWendt MarvinJWendt removed the needs refactor Something that needs to be refactored. label Jun 6, 2021
@MarvinJWendt
Copy link
Member

Hi @tw1nk, the PR is now live in v0.12.23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal-accepted Proposals which are accepted for implementation in the future
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants