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(cli): add methods to print to console #111

Merged
merged 4 commits into from
Jan 6, 2024

Conversation

czar0
Copy link
Contributor

@czar0 czar0 commented Dec 28, 2023

  • Columnize() uses the text/tabwriter standard library to print fields that are vertically aligned in columns and split by the | delimiter character.
  • GetValueByJSONTag() recursively searches for a string key within the JSON tags of a given object to return the value associated with it. This method uses command flags like --field where a single return value is expected.
  • The format for the printing - minwidth, tabwidth, padding, padchar - is configurable.
  • FromStruct() converts a struct into a Printable using, when available, JSON field names as keys.
  • customFormat() is a utility function to format numbers to avoid scientific notation and ensure they are printed as integers.

(A/N: This PR will make much more sense once I push the implementation for the block command 😄. Coming soon! 😎)

Output example for the complex struct (in tests):

name                | complex
list                |
                    | first
                    | second
nested              |
                    | value              | 500000000
                    | title              | hello
object              |
                    | obj1               | 1
                    | obj2               | -2
objList             |
                    | item2              | 2
                    | item1              | 1
                    |                    |
                    | item3              | 30000000
                    | item4              | 20000000
                    | item5              | 21234560
                    |                    |

- Columnize() is using text/tabwriter standard library to print fields and vertically aligned in columns, split by the `|` delimiter character.
- GetValueByJSONTag() recursively search for a string key within the JSON tags of a given object to return the value associated with it. This metho
d is used with command flags like `--field` where a single return value is expected.
- The format for the printing - minwidth, tabwidth, padding, padchar - is configurable.
- FromStruct() converts a struct into a Printable using, when available, JSON field names as keys.
- customFormat() is an utility function to format numbers and avoid scientific notation and ensure they are printed as integers.
@pkieltyka pkieltyka merged commit 8330d0b into 0xsequence:master Jan 6, 2024
6 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.

2 participants