-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
+2,723
−2,686
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
cae62e0
Update Command API
dduugg 0f2efd3
Port Homebrew::DevCmd::Audit
dduugg ee0c967
Port Homebrew::DevCmd::Bottle
dduugg ebc458a
Port Homebrew::DevCmd::BumpCaskPr
dduugg d873881
Port Homebrew::DevCmd::BumpFormulaPr
dduugg 1097496
Port Homebrew::DevCmd::BumpRevision
dduugg c70dc04
Port Homebrew::DevCmd::BumpUnversionedCask
dduugg df42e9c
Port Homebrew::DevCmd::Bump
dduugg 55a0991
Port Homebrew::DevCmd::Cat
dduugg 777ee12
Port Homebrew::DevCmd::Command
dduugg 0373e0d
Port Homebrew::DevCmd::Contributions
dduugg 6b19bc5
Style cleanup
dduugg bf9ebcc
Handle dashed commands
dduugg db9c5a5
Fix linux test
dduugg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# typed: true | ||
# frozen_string_literal: true | ||
|
||
require "abstract_command" | ||
require "env_config" | ||
require "cask/config" | ||
require "cli/args" | ||
|
@@ -19,9 +20,18 @@ class Parser | |
|
||
def self.from_cmd_path(cmd_path) | ||
cmd_args_method_name = Commands.args_method_name(cmd_path) | ||
cmd_name = cmd_args_method_name.to_s.delete_suffix("_args").tr("_", "-") | ||
|
||
begin | ||
Homebrew.send(cmd_args_method_name) if require?(cmd_path) | ||
if require?(cmd_path) | ||
cmd = Homebrew::AbstractCommand.command(cmd_name) | ||
if cmd | ||
cmd.parser | ||
else | ||
# FIXME: remove once commands are all subclasses of `AbstractCommand`: | ||
Homebrew.send(cmd_args_method_name) | ||
end | ||
end | ||
rescue NoMethodError => e | ||
raise if e.name.to_sym != cmd_args_method_name | ||
|
||
|
@@ -109,8 +119,10 @@ def self.global_options | |
] | ||
end | ||
|
||
sig { params(block: T.nilable(T.proc.bind(Parser).void)).void } | ||
def initialize(&block) | ||
sig { | ||
params(cmd: T.nilable(T.class_of(Homebrew::AbstractCommand)), block: T.nilable(T.proc.bind(Parser).void)).void | ||
} | ||
def initialize(cmd = nil, &block) | ||
@parser = OptionParser.new | ||
|
||
@parser.summary_indent = " " * 2 | ||
|
@@ -123,12 +135,18 @@ def initialize(&block) | |
|
||
@args = Homebrew::CLI::Args.new | ||
|
||
# Filter out Sorbet runtime type checking method calls. | ||
cmd_location = T.must(caller_locations).select do |location| | ||
T.must(location.path).exclude?("/gems/sorbet-runtime-") | ||
end.fetch(1) | ||
@command_name = T.must(cmd_location.label).chomp("_args").tr("_", "-") | ||
@is_dev_cmd = T.must(cmd_location.absolute_path).start_with?(Commands::HOMEBREW_DEV_CMD_PATH) | ||
if cmd | ||
@command_name = cmd.command_name | ||
@is_dev_cmd = cmd.name&.start_with?("Homebrew::DevCmd") | ||
else | ||
# FIXME: remove once commands are all subclasses of `AbstractCommand`: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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! |
||
# Filter out Sorbet runtime type checking method calls. | ||
cmd_location = T.must(caller_locations).select do |location| | ||
T.must(location.path).exclude?("/gems/sorbet-runtime-") | ||
end.fetch(1) | ||
@command_name = T.must(cmd_location.label).chomp("_args").tr("_", "-") | ||
@is_dev_cmd = T.must(cmd_location.absolute_path).start_with?(Commands::HOMEBREW_DEV_CMD_PATH) | ||
end | ||
|
||
@constraints = [] | ||
@conflicts = [] | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can be done in another PR: I think it would make sense to move
AbstractCommand
toHomebrew::CLI::AbstractCommand
.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 have no strong feelings on their either way.