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

Convert some dev commands to use AbstractCommand #16921

Merged
merged 14 commits into from Mar 20, 2024
Merged

Convert some dev commands to use AbstractCommand #16921

merged 14 commits into from Mar 20, 2024

Conversation

dduugg
Copy link
Sponsor Member

@dduugg dduugg commented Mar 19, 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?

This PR ports the first ten dev commands (alphabetically) to using AbstractCommand. (There are some minor changes to the Parser and AbstractCommand to better facilitate this.) I did some misc cleanup along the way (moving constants from top-level to inside the command class, using the args ivar instead of passing through to helper methods, making helper methods private, etc.)

I recommend reviewing with whitespace diffs disabled.

@dduugg dduugg marked this pull request as draft March 19, 2024 19:44
@dduugg dduugg marked this pull request as ready for review March 19, 2024 23:09
@command_name = cmd.command_name
@is_dev_cmd = cmd.name&.start_with?("Homebrew::DevCmd")
else
# FIXME: remove once commands are all subclasses of `AbstractCommand`:
Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

This is an especially nice change, IMO. No more inspecting the call stack to figure out the command!

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.

Really great work, I love it!


begin
Homebrew.send(cmd_args_method_name) if require?(cmd_path)
if require?(cmd_path)
cmd = Homebrew::AbstractCommand.command(cmd_name)
Copy link
Member

Choose a reason for hiding this comment

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

Can be done in another PR: I think it would make sense to move AbstractCommand to Homebrew::CLI::AbstractCommand.

Copy link
Member

Choose a reason for hiding this comment

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

I have no strong feelings on their either way.

Comment on lines +9 to +10
module DevCmd
class BumpRevision < AbstractCommand
Copy link
Member

Choose a reason for hiding this comment

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

Similar to above: I think it would make sense to move this either to Homebrew::CLI::BumpRevisionCommand (possibly with self.class.dev_command?), or to Homebrew::CLI::DevCmd::BumpRevision.

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

Possibly, feel free to put something together. Currently, Parser and AbstractCommand are tightly coupled in a way that should be avoided, Args still needs to be individually namespaced, commands need to be ported, etc., and I would instead encourage prioritizing that work instead.

I thought about a dev_cmd DSL. I went with the namespace approach rather than introducing more code, but the latter is probably preferred from a classic CS perspective…

Copy link
Member

Choose a reason for hiding this comment

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

Homebrew::CLI::BumpRevisionCommand (possibly with self.class.dev_command?), or to Homebrew::CLI::DevCmd::BumpRevision.

👎🏻 from me, I prefer the DevCmd namespacing as it:

  • better mirrors what's on disk
  • has fewer nested modules than the second option

Copy link
Member

Choose a reason for hiding this comment

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

better mirrors what's on disk

Renaming the files to follow the module naming would naturally be the consequence.

Copy link
Member

Choose a reason for hiding this comment

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

I would rather keep the files in the same place they have been for a long time and make the modules mirror that rather than move stuff around unnecessarily.

@dduugg dduugg enabled auto-merge March 20, 2024 17:44
@dduugg dduugg merged commit 0ac23c0 into master Mar 20, 2024
26 checks passed
@dduugg dduugg deleted the ported-cmds branch March 20, 2024 17:47
@github-actions github-actions bot added the outdated PR was locked due to age label Apr 21, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants