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 next batch of dev commands to use AbstractCommand #16937

Merged
merged 18 commits into from Mar 22, 2024
Merged

Conversation

dduugg
Copy link
Sponsor Member

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

Ports the next 15 dev commands to use AbstractCommand. See prior art in #16921

module DevCmd
class FormulaCmd < AbstractCommand
sig { returns(String) }
def self.command_name = "formula"
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.

For this command, as well as livecheck, naming the class in the usual manner (i.e. Formula and Livecheck) causes a bunch of type resolution errors in the command directories. Rather than resolve those to use fully-qualified paths, I gave the classes different names, and overrode their command_name values so that the command still works in the usual way.

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it's worth automatically stripping -cmd suffixes from the generated command_name so we don't need to do this every time. (And we can use self.command_name= in case we actually want to keep -cmd).

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.

Good call, I add automagical suffix deletion in the latest commit.

@dduugg dduugg changed the title Ported cmds Convert next batch of dev commands to use AbstractCommand Mar 22, 2024
Comment on lines +57 to +58
!Homebrew::EnvConfig.no_install_from_api? &&
!Homebrew::EnvConfig.no_env_hints? &&
Copy link
Member

Choose a reason for hiding this comment

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

Not your addition, but it seems nicer to hoist these conditions out of the loop so we don't need to recheck it for each path.

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.

Agreed, but would prefer to scope that to another PR

module DevCmd
class FormulaCmd < AbstractCommand
sig { returns(String) }
def self.command_name = "formula"
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it's worth automatically stripping -cmd suffixes from the generated command_name so we don't need to do this every time. (And we can use self.command_name= in case we actually want to keep -cmd).


# work around IRB modifying ARGV.
sig { params(argv: T.nilable(T::Array[String])).void }
def initialize(argv = nil) = super(argv || ARGV.dup.freeze)
Copy link
Member

Choose a reason for hiding this comment

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

Didn't realise you could do this (i.e. def foo(x) = bar(x)) now.

let(:url) { "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" }
let(:formula_file) { CoreTap.instance.new_formula_path("testball") }

it_behaves_like "parseable arguments"
it_behaves_like "parseable arguments", argv: ["foo"]
Copy link
Member

Choose a reason for hiding this comment

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

It seems weird to need to pass a garbage argv all over the place.

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.

Good point. I've updated the helper to create a suitable argv by inspecting the parser's @min_named_args ivar.

RSpec.describe "brew dispatch-build-bottle" do
it_behaves_like "parseable arguments"
RSpec.describe Homebrew::DevCmd::DispatchBuildBottle do
it_behaves_like "parseable arguments", argv: ["foo"]
Copy link
Member

Choose a reason for hiding this comment

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

Here too, re argv.

RSpec.describe "brew extract" do
it_behaves_like "parseable arguments"
RSpec.describe Homebrew::DevCmd::Extract do
it_behaves_like "parseable arguments", argv: ["foo", "bar"]
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should just be able to pass the minimum number of required arguments instead of having to pass a garbage array every time?

RSpec.describe "brew formula" do
it_behaves_like "parseable arguments"
RSpec.describe Homebrew::DevCmd::FormulaCmd do
it_behaves_like "parseable arguments", argv: ["foo"]
Copy link
Member

Choose a reason for hiding this comment

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

Ditto re argv.

RSpec.describe "brew pr-publish" do
it_behaves_like "parseable arguments"
RSpec.describe Homebrew::DevCmd::PrPublish do
it_behaves_like "parseable arguments", argv: ["foo"]
Copy link
Member

Choose a reason for hiding this comment

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

Garbage argv again.

@dduugg
Copy link
Sponsor Member Author

dduugg commented Mar 22, 2024

Great feedback, @carlocab, I super duper appreciate the time spent reviewing PRs like this. PTAL.

Copy link
Member

@carlocab carlocab left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @dduugg!

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.

Great work here @dduugg and thanks for the insightful comments @carlocab!

require "cmd/shared_examples/args_parse"
require "dev-cmd/install-bundler-gems"

RSpec.describe Homebrew::DevCmd::InstallBundlerGems do
Copy link
Member

Choose a reason for hiding this comment

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

Meta: might be nice to have a test some time for ensuring each command/dev-cmd has a test?

@MikeMcQuaid MikeMcQuaid merged commit 999ecf8 into master Mar 22, 2024
25 checks passed
@MikeMcQuaid MikeMcQuaid deleted the ported-cmds branch March 22, 2024 08:36
@github-actions github-actions bot added the outdated PR was locked due to age label Apr 22, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 22, 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

4 participants