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

Rewrite the CLI module using OO, and organize argparse #3175

Merged
merged 20 commits into from
Jul 22, 2024

Conversation

renanrodrigo
Copy link
Member

@renanrodrigo renanrodrigo commented Jun 19, 2024

Why is this needed?

This PR solves all of our problems because this will set a new standard for the Pro Client CLI, which will be leveraged for the new UX implementation.

  • Implement commands and arguments as classes
  • Simplify separation of concerns, maintainability and testing
  • Split the CLI into submodules
  • Test help text in behave

Test Steps

This PR should contain only refactors. Yep check tox and behave, small changes to help text


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

Copy link

github-actions bot commented Jun 19, 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

@renanrodrigo
Copy link
Member Author

@lucasmoura @orndorffgrant @dheyay I want to do this to ALL commands but please take preliminary looks to make sure you agree with the structure - easier to change earlier when less commands are implemented/affected

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.

👏 👏 👏 Excellent - big fan

How much should we convert to this at once? Should we just go for all of it? (each command in a separate commit, though)

uaclient/cli/commands.py Outdated Show resolved Hide resolved
Copy link
Contributor

@dheyay dheyay 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, will make the CLI module readable 👀 🎈

(Should have just left this as a comment, since this is WIP)

@renanrodrigo
Copy link
Member Author

@orndorffgrant I want to do this to all commands, yes - maybe incrementally, simple ones in this PR, if I find something more tricky (and I will) I can send it separate for ease of review. As it is a refactor anyway, we can merge without usability changes

@orndorffgrant
Copy link
Collaborator

orndorffgrant commented Jun 26, 2024

@orndorffgrant I want to do this to all commands, yes - maybe incrementally, simple ones in this PR, if I find something more tricky (and I will) I can send it separate for ease of review. As it is a refactor anyway, we can merge without usability changes

@renanrodrigo makes sense. Maybe can you prioritize the subcommands that have their own module? The we'd only have "new" commands in this form and "old" commands in cli/__init__.py (and no "in-between" commands in the better-but-not-as-good separate module form)

@renanrodrigo
Copy link
Member Author

@renanrodrigo makes sense. Maybe can you prioritize the subcommands that have their own module? The we'd only have "new" commands in this form and "old" commands in cli/__init__.py (and no "in-between" commands in the better-but-not-as-good separate module form)

Not sure - some of those have been separated exactly because they are more complicated somehow. I'll try and see what happens

@renanrodrigo renanrodrigo force-pushed the object-cli branch 5 times, most recently from edd90dd to d127c36 Compare July 3, 2024 19:06
Those classes will shape our CLI entrypoints with some OO so we write
less boilerplate code and organize things better.

Commands and options will be instances of those classes.

Signed-off-by: Renan Rodrigo <[email protected]>
we want to ensure long_name and help, but anything else just passes by.

Signed-off-by: Renan Rodrigo <[email protected]>
Grouping arguments enables us to create logical groups of arguments when
dealing with help text in the future, and to create mutually exclusive
groups - which are implemented in the code in one way or the other - and
need to be standardized.
@renanrodrigo renanrodrigo force-pushed the object-cli branch 4 times, most recently from 70477cf to c230f7a Compare July 12, 2024 17:10
@renanrodrigo renanrodrigo marked this pull request as ready for review July 12, 2024 17:11
@renanrodrigo
Copy link
Member Author

@lucasmoura @orndorffgrant @dheyay this is now ready for review. Please keep in mind:

  • the help text is standardized and broken - next PR will target only help outputs
  • there are some workarounds that I could improve, but not remove.
  • I could rewrite a lot more, but focused on standardizing and organizing argparse magic.

@renanrodrigo renanrodrigo changed the title WIP: CLI refactor CLI refactor Jul 12, 2024
@renanrodrigo renanrodrigo changed the title CLI refactor Rewrite the CLI module using OO, and organizing argparse Jul 12, 2024
@renanrodrigo renanrodrigo changed the title Rewrite the CLI module using OO, and organizing argparse Rewrite the CLI module using OO, and organize argparse Jul 12, 2024
There is no need to create a whole new action for this using the new
approach to the CLI. Furthermore, we already do some arg surgery, and
this makes parse_args return immmeditely without further burden.

And it does show the version.

Signed-off-by: Renan Rodrigo <[email protected]>
@renanrodrigo renanrodrigo force-pushed the object-cli branch 2 times, most recently from e74418e to 61fbe4d Compare July 13, 2024 14:53
And the parser is now ProArgumentParser

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.

Approving with the understanding that we need at least the most basic form of the follow up --help PR merged. Specifically, the usage line for sub-subcommands (e.g. pro config show) is broken after this PR.

And a nit that doesn't block this PR: I'd like to change the help behave tests to test stdout equality rather than using a regexp. We can put "optional arguments" vs "options" into an example table variable per ubuntu release.

@orndorffgrant orndorffgrant merged commit 48308d3 into next-v34 Jul 22, 2024
20 of 26 checks passed
@orndorffgrant orndorffgrant deleted the object-cli branch July 22, 2024 20:04
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.

4 participants