Skip to content

Commit

Permalink
Merge pull request #17123 from Homebrew/namespaced-args
Browse files Browse the repository at this point in the history
Create individually namespace args for each command
  • Loading branch information
MikeMcQuaid authored Apr 23, 2024
2 parents a49fc9d + 1980e62 commit 0516f47
Show file tree
Hide file tree
Showing 99 changed files with 594 additions and 98 deletions.
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 @@ def run

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
# 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

0 comments on commit 0516f47

Please sign in to comment.