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

Create individually namespace args for each command #17123

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Library/Homebrew/abstract_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class AbstractCommand
abstract!

class << self
sig { returns(T.nilable(T.class_of(CLI::Args))) }
attr_reader :args_class

sig { returns(String) }
def command_name = Utils.underscore(T.must(name).split("::").fetch(-1)).tr("_", "-").delete_suffix("-cmd")

Expand All @@ -37,6 +40,7 @@ def parser = CLI::Parser.new(self, &@parser_block)
sig { params(block: T.proc.bind(CLI::Parser).void).void }
def cmd_args(&block)
@parser_block = T.let(block, T.nilable(T.proc.void))
@args_class = T.let(const_set(:Args, Class.new(CLI::Args)), T.nilable(T.class_of(CLI::Args)))
end
end

Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/cask/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def self.defaults

sig { params(args: Homebrew::CLI::Args).returns(T.attached_class) }
def self.from_args(args)
args = T.unsafe(args)
new(explicit: {
appdir: args.appdir,
keyboard_layoutdir: args.keyboard_layoutdir,
Expand Down
21 changes: 21 additions & 0 deletions Library/Homebrew/cli/args.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,25 @@ class Homebrew::CLI::Args

sig { returns(T::Boolean) }
def verbose?; end

# FIXME: The methods below are not defined by Args, but are valid because Args inherits from OpenStruct
# We should instead be using type guards to check if the method is defined on the object before calling it

sig { returns(T.nilable(String)) }
def arch; end

sig { returns(T::Boolean) }
def build_from_source?; end

sig { returns(T::Boolean) }
def cask?; end

sig { returns(T::Boolean) }
def formula?; end

sig { returns(T::Boolean) }
def include_test?; end

sig { returns(T.nilable(String)) }
def os; end
end
2 changes: 1 addition & 1 deletion Library/Homebrew/cli/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def initialize(cmd = nil, &block)
# Disable default handling of `--help` switch.
@parser.base.long.delete("help")

@args = T.let(Homebrew::CLI::Args.new, Homebrew::CLI::Args)
@args = T.let((cmd&.args_class || Args).new, Args)

if cmd
@command_name = T.let(cmd.command_name, String)
Expand Down
3 changes: 2 additions & 1 deletion Library/Homebrew/dev-cmd/typecheck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@

HOMEBREW_LIBRARY_PATH.cd do
if update
safe_system "bundle", "exec", "tapioca", "dsl"
workers = args.debug? ? ["--workers=1"] : []
safe_system "bundle", "exec", "tapioca", "dsl", *workers

Check warning on line 52 in Library/Homebrew/dev-cmd/typecheck.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/typecheck.rb#L52

Added line #L52 was not covered by tests
# Prefer adding args here: Library/Homebrew/sorbet/tapioca/config.yml
tapioca_args = args.update_all? ? ["--all"] : []

Expand Down
7 changes: 6 additions & 1 deletion Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/analytics.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/autoremove.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/cache.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/caskroom.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/cellar.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/cleanup_cmd.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/config.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/deps.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/desc.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/developer.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/docs.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/doctor.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/env.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/fetch_cmd.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/gist_logs.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/help_cmd.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/home.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/info.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/install_cmd.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/leaves.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/link.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/list.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/log.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading