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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create individually namespace args for each command #17123

Merged
merged 2 commits into from Apr 23, 2024
Merged

Conversation

dduugg
Copy link
Sponsor Member

@dduugg dduugg commented Apr 21, 2024

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

As a follow-up to #16814 this PR makes the args for each command individually namespace. The advantages include a browsable API (have a look at https://rubydoc.brew.sh/Homebrew/CLI/Args.html before this goes in 馃槵), better type annotations (some commands define the same arg under different conditions), better type-checking (referencing an arg from another command will result in an error).

To do this, an Args class under the commands namespace is dynamically created when cmd_args is evaluated. This lets us implement this change without breaking the command API, though it does introduce a fair amount of Ruby magic.

(The first commit does the heavy lifting, the second applies it with brew tc --update.)

(Opening in draft mode for initial feedback.)

@dduugg dduugg marked this pull request as draft April 21, 2024 23:25
@apainintheneck
Copy link
Contributor

I like this approach. It makes sense to me.

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Love the approach! Nice work @dduugg!

@dduugg dduugg marked this pull request as ready for review April 22, 2024 16:02
@dduugg
Copy link
Sponsor Member Author

dduugg commented Apr 22, 2024

Opening up for general review. On re-reading, I'm actually pleasantly surprised how easy this was to wire up (~5 lines of runtime code).

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Approving again and merging, thanks @dduugg!

@MikeMcQuaid MikeMcQuaid merged commit 0516f47 into master Apr 23, 2024
26 checks passed
@MikeMcQuaid MikeMcQuaid deleted the namespaced-args branch April 23, 2024 07:27
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.

None yet

3 participants