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
Conversation
Library/Homebrew/dev-cmd/formula.rb
Outdated
module DevCmd | ||
class FormulaCmd < AbstractCommand | ||
sig { returns(String) } | ||
def self.command_name = "formula" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
).
There was a problem hiding this comment.
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.
!Homebrew::EnvConfig.no_install_from_api? && | ||
!Homebrew::EnvConfig.no_env_hints? && |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
Library/Homebrew/dev-cmd/formula.rb
Outdated
module DevCmd | ||
class FormulaCmd < AbstractCommand | ||
sig { returns(String) } | ||
def self.command_name = "formula" |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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"] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"] |
There was a problem hiding this comment.
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"] |
There was a problem hiding this comment.
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"] |
There was a problem hiding this comment.
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"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Garbage argv
again.
Great feedback, @carlocab, I super duper appreciate the time spent reviewing PRs like this. PTAL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @dduugg!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
require "cmd/shared_examples/args_parse" | ||
require "dev-cmd/install-bundler-gems" | ||
|
||
RSpec.describe Homebrew::DevCmd::InstallBundlerGems do |
There was a problem hiding this comment.
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?
brew style
with your changes locally?brew typecheck
with your changes locally?brew tests
with your changes locally?Ports the next 15 dev commands to use
AbstractCommand
. See prior art in #16921