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

Remove OpenStruct from CLI::Args #18847

Merged
merged 11 commits into from
Dec 11, 2024
Merged

Remove OpenStruct from CLI::Args #18847

merged 11 commits into from
Dec 11, 2024

Conversation

dduugg
Copy link
Member

@dduugg dduugg commented Dec 1, 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?

Resolves #18777

  • Retains the @table attr that OpenStruct used, but it is now exclusively for args (not metadata like named and remaining). I'm open to renaming the attr.
  • missing_method dispatch is removed, only defined methods are allowed
  • A generic set_arg method is provided, to allow setting args from the parser. There is no corresponding getter, because I want to encourage explicit invocations. The usual ruby escape hatches (e.g. instance_variable_get) are available if needed 😞.
  • Within the args class, I've replaced arg lookup methods with @table lookups, because the methods aren't necessarily defined. It's a bit of an eyesore, but IMO preferable to defining them unnecessarily, or using respond_to? guards.

@dduugg dduugg marked this pull request as draft December 1, 2024 00:55
@dduugg
Copy link
Member Author

dduugg commented Dec 3, 2024

Promising start, passes tests locally, but has an issue where methods are being defined twice – once when the cmd_args are read, and once when the args are set. I should be able to refine this approach by defining and setting attributes instead, then we'll see what the next blocker is.

Library/Homebrew/cli/error.rb Outdated Show resolved Hide resolved
@dduugg dduugg force-pushed the no-ostruct branch 5 times, most recently from 203bd8a to a738f8d Compare December 7, 2024 04:29
@dduugg dduugg mentioned this pull request Dec 7, 2024
7 tasks
@dduugg dduugg marked this pull request as ready for review December 10, 2024 18:59
@dduugg
Copy link
Member Author

dduugg commented Dec 10, 2024

Marking as ready for review. Hopefully this is a reasonable, incremental improvement over the previous 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.

Thanks @dduugg! Looks good to me to merge when you're around for a few hours to deal with any post-merge 💥

@dduugg dduugg added this pull request to the merge queue Dec 11, 2024
Merged via the queue into master with commit 563c2b1 Dec 11, 2024
38 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.

Remove OpenStruct dependency
2 participants