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

Printing standardized output for CLI commands #3323

Merged
merged 6 commits into from
Sep 30, 2024
Merged

Printing standardized output for CLI commands #3323

merged 6 commits into from
Sep 30, 2024

Conversation

renanrodrigo
Copy link
Member

Why is this needed?

This PR solves all of our problems because it brings some tweaks to the Table implementation, includes the indented Block and SuggestionBlock implementation and adds a helper function which considers the formatter config when returning text.
This is the last base PR for the CLI before the commands start to appear.

Test Steps

Unit tests cover the functionality
Integration and such will come with the commands


  • (un)check this to re-run the checklist action

Copy link

github-actions bot commented Sep 23, 2024

PR Checklist

How to use this checklist

How to use this checklist

PR Author

For each section, check a box when it is true.
Uncheck a box if it becomes un-true.
Then check the box at the bottom of the PR description to re-run the action that creates this checklist.
The action that creates and updates this comment will retain your edits.
The action will fail if the checklist is not completed.

PR Reviewer

Check that the PR checklist action did not fail.
Double check that the author filled out the checklist accurately.
If you disagree with a checklist item, start a conversation.
For example, the author may say they don't think integration tests are necessary, but you may disagree.

Bug References

None.

Confirm

  • I've properly referenced all bugs that this PR fixes
How to properly reference fixed bugs
  • If this PR is related to a Jira item, include an SC-1234 reference in the PR title
  • If this PR is fixes a GitHub issue, include a Fixes: #1234 reference in the commit that fixes the issue
  • If this PR is fixes a Launchpad bug, include a LP: #12345678 reference in the commit that fixes the issue

Test Updates

Unit Tests

  • I have updated or added any unit tests accordingly
  • No unit test changes are necessary for this change

Integration Tests

  • I have updated or added any integration tests accordingly
  • No integration test changes are necessary for this change

Documentation

  • Changes here need to be documented and I have referenced the docs PR in the description
  • No documentation updates are necessary for this change

Does this PR require review from someone outside the core ubuntu-pro-client team?

  • Yes, and I have requested those reviews via GitHub
  • No

uaclient/cli/formatter.py Outdated Show resolved Hide resolved
uaclient/cli/formatter.py Outdated Show resolved Hide resolved
@@ -133,11 +133,12 @@ def _get_column_sizes(self) -> List[int]:
return column_sizes

def __str__(self) -> str:
rows = self.rows
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need the rows variable if the fix is applied on new_rows.append call ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because the new_rows thing is only done if the table exceeds the line length. If there is no line exceeding the available space, then the whole thing short-circuits to using the actual content in self.rows, without change.

Copy link
Collaborator

@orndorffgrant orndorffgrant left a comment

Choose a reason for hiding this comment

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

As part of our process to get ready for v35, I have rebased next-v35 onto main. As a result, next-v35 is now obsolete. Please rebase this on main and target the PR to main.

@renanrodrigo
Copy link
Member Author

Hopefully rebased this correctly against main

@renanrodrigo
Copy link
Member Author

@lucasmoura I have created the ABC to represent Blocks and Tables and something else. That suffices for not caring about the isinstance call if we want to add new representations or derivatives of those in the future - so I think this is enough for the call; no need to convert anything nonstandard to an instance of that class. PTALALMK

@renanrodrigo
Copy link
Member Author

bad, bad fix CI

Make the __str__ method work even when max_length is changed after the
instance is created

Signed-off-by: Renan Rodrigo <[email protected]>
Instead of passing it to the constructor, optionally pass it to a
to_string method

Signed-off-by: Renan Rodrigo <[email protected]>
Indented Blocks standardize indentation through the CLI, and Suggestion
Blocks take the suggestion configuration into consideration.

Signed-off-by: Renan Rodrigo <[email protected]>
Add a helper function to remove unwanted symbols in the CLI outputs.

Signed-off-by: Renan Rodrigo <[email protected]>
This eases the isinstance check for Blocks, Tables and whatnot by
creating an abstract superclass which represents those, defining
to_string in its interface for consistency.

Signed-off-by: Renan Rodrigo <[email protected]>
Copy link
Collaborator

@orndorffgrant orndorffgrant left a comment

Choose a reason for hiding this comment

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

Thanks!

@orndorffgrant orndorffgrant merged commit 4027b9b into main Sep 30, 2024
20 of 24 checks passed
@orndorffgrant orndorffgrant deleted the pro-print branch September 30, 2024 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants