Add more type signatures.

This commit is contained in:
Markus Reiter 2020-10-20 12:03:48 +02:00
parent c602090624
commit da9289eff0
237 changed files with 1223 additions and 98 deletions

View File

@ -297,15 +297,9 @@ Sorbet/ConstantsFromStrings:
Style/AccessModifierDeclarations: Style/AccessModifierDeclarations:
Enabled: false Enabled: false
# don't group nicely documented or private attr_readers # Conflicts with type signatures on `attr_*`s.
Style/AccessorGrouping: Style/AccessorGrouping:
Exclude: Enabled: false
- 'Homebrew/formula.rb'
- 'Homebrew/formulary.rb'
- 'Homebrew/migrator.rb'
- 'Homebrew/resource.rb'
- 'Homebrew/system_command.rb'
- 'Homebrew/tap.rb'
# make rspec formatting more flexible # make rspec formatting more flexible
Style/BlockDelimiters: Style/BlockDelimiters:

View File

@ -8,6 +8,8 @@ require "json"
# #
# @api private # @api private
class Bintray class Bintray
extend T::Sig
include Context include Context
API_URL = "https://api.bintray.com" API_URL = "https://api.bintray.com"
@ -15,6 +17,7 @@ class Bintray
class Error < RuntimeError class Error < RuntimeError
end end
sig { returns(String) }
def inspect def inspect
"#<Bintray: org=#{@bintray_org}>" "#<Bintray: org=#{@bintray_org}>"
end end

View File

@ -7,6 +7,8 @@ module Cask
# #
# @api private # @api private
class AbstractArtifact class AbstractArtifact
extend T::Sig
include Comparable include Comparable
extend Predicable extend Predicable
@ -132,6 +134,7 @@ module Cask
cask.config cask.config
end end
sig { returns(String) }
def to_s def to_s
"#{summarize} (#{self.class.english_name})" "#{summarize} (#{self.class.english_name})"
end end

View File

@ -15,6 +15,8 @@ module Cask
# #
# @api private # @api private
class AbstractUninstall < AbstractArtifact class AbstractUninstall < AbstractArtifact
extend T::Sig
ORDERED_DIRECTIVES = [ ORDERED_DIRECTIVES = [
:early_script, :early_script,
:launchctl, :launchctl,
@ -53,6 +55,7 @@ module Cask
directives.to_h directives.to_h
end end
sig { returns(String) }
def summarize def summarize
to_h.flat_map { |key, val| Array(val).map { |v| "#{key.inspect} => #{v.inspect}" } }.join(", ") to_h.flat_map { |key, val| Array(val).map { |v| "#{key.inspect} => #{v.inspect}" } }.join(", ")
end end
@ -128,6 +131,7 @@ module Cask
end end
end end
sig { returns(String) }
def automation_access_instructions def automation_access_instructions
"Enable Automation Access for “Terminal > System Events” in " \ "Enable Automation Access for “Terminal > System Events” in " \
"“System Preferences > Security > Privacy > Automation” if you haven't already." "“System Preferences > Security > Privacy > Automation” if you haven't already."

View File

@ -12,6 +12,9 @@ module Cask
# #
# @api private # @api private
class Artifact < Moved class Artifact < Moved
extend T::Sig
sig { returns(String) }
def self.english_name def self.english_name
"Generic Artifact" "Generic Artifact"
end end

View File

@ -9,6 +9,9 @@ module Cask
# #
# @api private # @api private
class Mdimporter < Moved class Mdimporter < Moved
extend T::Sig
sig { returns(String) }
def self.english_name def self.english_name
"Spotlight metadata importer" "Spotlight metadata importer"
end end

View File

@ -9,6 +9,9 @@ module Cask
# #
# @api private # @api private
class Moved < Relocated class Moved < Relocated
extend T::Sig
sig { returns(String) }
def self.english_description def self.english_description
"#{english_name}s" "#{english_name}s"
end end

View File

@ -9,6 +9,9 @@ module Cask
# #
# @api private # @api private
class Prefpane < Moved class Prefpane < Moved
extend T::Sig
sig { returns(String) }
def self.english_name def self.english_name
"Preference Pane" "Preference Pane"
end end

View File

@ -9,6 +9,9 @@ module Cask
# #
# @api private # @api private
class Qlplugin < Moved class Qlplugin < Moved
extend T::Sig
sig { returns(String) }
def self.english_name def self.english_name
"QuickLook Plugin" "QuickLook Plugin"
end end

View File

@ -12,6 +12,8 @@ module Cask
# #
# @api private # @api private
class Relocated < AbstractArtifact class Relocated < AbstractArtifact
extend T::Sig
def self.from_args(cask, *args) def self.from_args(cask, *args)
source_string, target_hash = args source_string, target_hash = args
@ -49,6 +51,7 @@ module Cask
end end
end end
sig { returns(String) }
def summarize def summarize
target_string = @target_string.empty? ? "" : " -> #{@target_string}" target_string = @target_string.empty? ? "" : " -> #{@target_string}"
"#{@source_string}#{target_string}" "#{@source_string}#{target_string}"

View File

@ -9,16 +9,20 @@ module Cask
# #
# @api private # @api private
class StageOnly < AbstractArtifact class StageOnly < AbstractArtifact
extend T::Sig
def self.from_args(cask, *args) def self.from_args(cask, *args)
raise CaskInvalidError.new(cask.token, "'stage_only' takes only a single argument: true") if args != [true] raise CaskInvalidError.new(cask.token, "'stage_only' takes only a single argument: true") if args != [true]
new(cask) new(cask)
end end
sig { returns(T::Array[T::Boolean]) }
def to_a def to_a
[true] [true]
end end
sig { returns(String) }
def summarize def summarize
"true" "true"
end end

View File

@ -9,10 +9,14 @@ module Cask
# #
# @api private # @api private
class Suite < Moved class Suite < Moved
extend T::Sig
sig { returns(String) }
def self.english_name def self.english_name
"App Suite" "App Suite"
end end
sig { returns(Symbol) }
def self.dirmethod def self.dirmethod
:appdir :appdir
end end

View File

@ -9,10 +9,14 @@ module Cask
# #
# @api private # @api private
class Symlinked < Relocated class Symlinked < Relocated
extend T::Sig
sig { returns(String) }
def self.link_type_english_name def self.link_type_english_name
"Symlink" "Symlink"
end end
sig { returns(String) }
def self.english_description def self.english_description
"#{english_name} #{link_type_english_name}s" "#{english_name} #{link_type_english_name}s"
end end

View File

@ -13,6 +13,8 @@ module Cask
# #
# @api private # @api private
class Audit class Audit
extend T::Sig
extend Predicable extend Predicable
attr_reader :cask, :download attr_reader :cask, :download
@ -117,6 +119,7 @@ module Cask
end end
end end
sig { returns(String) }
def summary def summary
summary = ["audit for #{cask}: #{result}"] summary = ["audit for #{cask}: #{result}"]
@ -416,6 +419,7 @@ module Cask
core_tap.formula_names core_tap.formula_names
end end
sig { returns(String) }
def core_formula_url def core_formula_url
"#{core_tap.default_remote}/blob/HEAD/Formula/#{cask.token}.rb" "#{core_tap.default_remote}/blob/HEAD/Formula/#{cask.token}.rb"
end end

View File

@ -12,6 +12,8 @@ module Cask
# #
# @api private # @api private
class Cask class Cask
extend T::Sig
extend Enumerable extend Enumerable
extend Forwardable extend Forwardable
extend Searchable extend Searchable
@ -64,6 +66,7 @@ module Cask
define_method(method_name) { |&block| @dsl.send(method_name, &block) } define_method(method_name) { |&block| @dsl.send(method_name, &block) }
end end
sig { returns(T::Array[[String, String]]) }
def timestamped_versions def timestamped_versions
Pathname.glob(metadata_timestamped_path(version: "*", timestamp: "*")) Pathname.glob(metadata_timestamped_path(version: "*", timestamp: "*"))
.map { |p| p.relative_path_from(p.parent.parent) } .map { |p| p.relative_path_from(p.parent.parent) }
@ -89,6 +92,7 @@ module Cask
!versions.empty? !versions.empty?
end end
sig { returns(T.nilable(Time)) }
def install_time def install_time
_, time = timestamped_versions.last _, time = timestamped_versions.last
return unless time return unless time

View File

@ -90,6 +90,8 @@ module Cask
# Loads a cask from a URI. # Loads a cask from a URI.
class FromURILoader < FromPathLoader class FromURILoader < FromPathLoader
extend T::Sig
def self.can_load?(ref) def self.can_load?(ref)
uri_regex = ::URI::DEFAULT_PARSER.make_regexp uri_regex = ::URI::DEFAULT_PARSER.make_regexp
return false unless ref.to_s.match?(Regexp.new("\\A#{uri_regex.source}\\Z", uri_regex.options)) return false unless ref.to_s.match?(Regexp.new("\\A#{uri_regex.source}\\Z", uri_regex.options))
@ -103,6 +105,7 @@ module Cask
attr_reader :url attr_reader :url
sig { params(url: T.any(URI::Generic, String)).void }
def initialize(url) def initialize(url)
@url = URI(url) @url = URI(url)
super Cache.path/File.basename(@url.path) super Cache.path/File.basename(@url.path)
@ -177,10 +180,13 @@ module Cask
# Pseudo-loader which raises an error when trying to load the corresponding cask. # Pseudo-loader which raises an error when trying to load the corresponding cask.
class NullLoader < FromPathLoader class NullLoader < FromPathLoader
extend T::Sig
def self.can_load?(*) def self.can_load?(*)
true true
end end
sig { params(ref: T.any(String, Pathname)).void }
def initialize(ref) def initialize(ref)
token = File.basename(ref, ".rb") token = File.basename(ref, ".rb")
super CaskLoader.default_path(token) super CaskLoader.default_path(token)

View File

@ -38,6 +38,8 @@ module Cask
# #
# @api private # @api private
class Cmd class Cmd
extend T::Sig
include Context include Context
ALIASES = { ALIASES = {
@ -61,6 +63,7 @@ module Cask
Cmd::Upgrade => "brew upgrade --cask", Cmd::Upgrade => "brew upgrade --cask",
}.freeze }.freeze
sig { returns(String) }
def self.description def self.description
max_command_length = Cmd.commands.map(&:length).max max_command_length = Cmd.commands.map(&:length).max

View File

@ -7,18 +7,24 @@ module Cask
# #
# @api private # @api private
class Cache < AbstractCommand class Cache < AbstractCommand
extend T::Sig
sig { override.returns(T.nilable(T.any(Integer, Symbol))) }
def self.min_named def self.min_named
:cask :cask
end end
sig { returns(String) }
def self.description def self.description
"Display the file used to cache a <cask>." "Display the file used to cache a <cask>."
end end
sig { returns(String) }
def self.command_name def self.command_name
"--cache" "--cache"
end end
sig { void }
def run def run
casks.each do |cask| casks.each do |cask|
puts self.class.cached_location(cask) puts self.class.cached_location(cask)

View File

@ -9,16 +9,22 @@ module Cask
# #
# @api private # @api private
class AbstractCommand class AbstractCommand
extend T::Sig
extend T::Helpers
include Homebrew::Search include Homebrew::Search
sig { returns(T.nilable(T.any(Integer, Symbol))) }
def self.min_named def self.min_named
nil nil
end end
sig { returns(T.nilable(Integer)) }
def self.max_named def self.max_named
nil nil
end end
sig { returns(String) }
def self.banner_args def self.banner_args
if min_named == :cask && max_named != 1 if min_named == :cask && max_named != 1
" <cask>" " <cask>"
@ -29,6 +35,7 @@ module Cask
end end
end end
sig { returns(String) }
def self.banner_headline def self.banner_headline
"`#{command_name}` [<options>]#{banner_args}" "`#{command_name}` [<options>]#{banner_args}"
end end
@ -72,24 +79,29 @@ module Cask
end end
end end
sig { returns(String) }
def self.command_name def self.command_name
@command_name ||= name.sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1_\2').downcase @command_name ||= name.sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1_\2').downcase
end end
sig { returns(T::Boolean) }
def self.abstract? def self.abstract?
name.split("::").last.match?(/^Abstract[^a-z]/) name.split("::").last.match?(/^Abstract[^a-z]/)
end end
sig { returns(T::Boolean) }
def self.visible? def self.visible?
true true
end end
sig { returns(String) }
def self.help def self.help
parser.generate_help_text parser.generate_help_text
end end
sig { returns(String) }
def self.short_description def self.short_description
description.split(".").first description[/\A[^.]*\./]
end end
def self.run(*args) def self.run(*args)

View File

@ -7,10 +7,14 @@ module Cask
# #
# @api private # @api private
class AbstractInternalCommand < AbstractCommand class AbstractInternalCommand < AbstractCommand
extend T::Sig
sig { returns(String) }
def self.command_name def self.command_name
super.sub(/^internal_/i, "_") super.sub(/^internal_/i, "_")
end end
sig { returns(T::Boolean) }
def self.visible? def self.visible?
false false
end end

View File

@ -9,6 +9,9 @@ module Cask
# #
# @api private # @api private
class Audit < AbstractCommand class Audit < AbstractCommand
extend T::Sig
sig { returns(String) }
def self.description def self.description
<<~EOS <<~EOS
Check <cask> for Homebrew coding style violations. This should be run before Check <cask> for Homebrew coding style violations. This should be run before
@ -37,6 +40,7 @@ module Cask
end end
end end
sig { void }
def run def run
require "cask/auditor" require "cask/auditor"

View File

@ -7,14 +7,19 @@ module Cask
# #
# @api private # @api private
class Cat < AbstractCommand class Cat < AbstractCommand
extend T::Sig
sig { override.returns(T.nilable(T.any(Integer, Symbol))) }
def self.min_named def self.min_named
:cask :cask
end end
sig { returns(String) }
def self.description def self.description
"Dump raw source of a <cask> to the standard output." "Dump raw source of a <cask> to the standard output."
end end
sig { void }
def run def run
casks.each do |cask| casks.each do |cask|
if Homebrew::EnvConfig.bat? if Homebrew::EnvConfig.bat?

View File

@ -7,14 +7,19 @@ module Cask
# #
# @api private # @api private
class Create < AbstractCommand class Create < AbstractCommand
extend T::Sig
sig { override.returns(T.nilable(T.any(Integer, Symbol))) }
def self.min_named def self.min_named
:cask :cask
end end
sig { override.returns(T.nilable(Integer)) }
def self.max_named def self.max_named
1 1
end end
sig { returns(String) }
def self.description def self.description
"Creates the given <cask> and opens it in an editor." "Creates the given <cask> and opens it in an editor."
end end
@ -25,6 +30,7 @@ module Cask
raise UsageError, "Only one cask can be created at a time." raise UsageError, "Only one cask can be created at a time."
end end
sig { void }
def run def run
cask_token = args.named.first cask_token = args.named.first
cask_path = CaskLoader.path(cask_token) cask_path = CaskLoader.path(cask_token)

View File

@ -7,14 +7,19 @@ module Cask
# #
# @api private # @api private
class Doctor < AbstractCommand class Doctor < AbstractCommand
extend T::Sig
sig { override.returns(T.nilable(Integer)) }
def self.max_named def self.max_named
0 0
end end
sig { returns(String) }
def self.description def self.description
"Checks for configuration issues." "Checks for configuration issues."
end end
sig { void }
def run def run
require "diagnostic" require "diagnostic"

View File

@ -7,14 +7,19 @@ module Cask
# #
# @api private # @api private
class Edit < AbstractCommand class Edit < AbstractCommand
extend T::Sig
sig { override.returns(T.nilable(T.any(Integer, Symbol))) }
def self.min_named def self.min_named
:cask :cask
end end
sig { override.returns(T.nilable(Integer)) }
def self.max_named def self.max_named
1 1
end end
sig { returns(String) }
def self.description def self.description
"Open the given <cask> for editing." "Open the given <cask> for editing."
end end
@ -25,6 +30,7 @@ module Cask
raise UsageError, "Only one cask can be edited at a time." raise UsageError, "Only one cask can be edited at a time."
end end
sig { void }
def run def run
exec_editor cask_path exec_editor cask_path
rescue CaskUnavailableError => e rescue CaskUnavailableError => e

View File

@ -7,6 +7,9 @@ module Cask
# #
# @api private # @api private
class Fetch < AbstractCommand class Fetch < AbstractCommand
extend T::Sig
sig { override.returns(T.nilable(T.any(Integer, Symbol))) }
def self.min_named def self.min_named
:cask :cask
end end
@ -18,10 +21,12 @@ module Cask
end end
end end
sig { returns(String) }
def self.description def self.description
"Downloads remote application files to local cache." "Downloads remote application files to local cache."
end end
sig { void }
def run def run
require "cask/download" require "cask/download"
require "cask/installer" require "cask/installer"

View File

@ -7,14 +7,19 @@ module Cask
# #
# @api private # @api private
class Help < AbstractCommand class Help < AbstractCommand
extend T::Sig
sig { override.returns(T.nilable(Integer)) }
def self.max_named def self.max_named
1 1
end end
sig { returns(String) }
def self.description def self.description
"Print help for `cask` commands." "Print help for `cask` commands."
end end
sig { void }
def run def run
if args.named.empty? if args.named.empty?
puts Cmd.parser.generate_help_text puts Cmd.parser.generate_help_text

View File

@ -7,10 +7,14 @@ module Cask
# #
# @api private # @api private
class Home < AbstractCommand class Home < AbstractCommand
extend T::Sig
sig { returns(String) }
def self.description def self.description
"Opens the homepage of the given <cask>. If no cask is given, opens the Homebrew homepage." "Opens the homepage of the given <cask>. If no cask is given, opens the Homebrew homepage."
end end
sig { void }
def run def run
if casks.none? if casks.none?
odebug "Opening project homepage" odebug "Opening project homepage"

View File

@ -9,10 +9,14 @@ module Cask
# #
# @api private # @api private
class Info < AbstractCommand class Info < AbstractCommand
extend T::Sig
sig { override.returns(T.nilable(T.any(Integer, Symbol))) }
def self.min_named def self.min_named
:cask :cask
end end
sig { returns(String) }
def self.description def self.description
"Displays information about the given <cask>." "Displays information about the given <cask>."
end end
@ -42,6 +46,7 @@ module Cask
end end
end end
sig { void }
def run def run
if args.json == "v1" if args.json == "v1"
puts JSON.generate(args.named.to_casks.map(&:to_h)) puts JSON.generate(args.named.to_casks.map(&:to_h))

View File

@ -7,10 +7,14 @@ module Cask
# #
# @api private # @api private
class Install < AbstractCommand class Install < AbstractCommand
extend T::Sig
sig { override.returns(T.nilable(T.any(Integer, Symbol))) }
def self.min_named def self.min_named
:cask :cask
end end
sig { returns(String) }
def self.description def self.description
"Installs the given <cask>." "Installs the given <cask>."
end end
@ -34,6 +38,7 @@ module Cask
end end
end end
sig { void }
def run def run
self.class.install_casks( self.class.install_casks(
*casks, *casks,

View File

@ -7,14 +7,19 @@ module Cask
# #
# @api private # @api private
class InternalHelp < AbstractInternalCommand class InternalHelp < AbstractInternalCommand
extend T::Sig
sig { override.returns(T.nilable(Integer)) }
def self.max_named def self.max_named
0 0
end end
sig { returns(String) }
def self.description def self.description
"Print help for unstable internal-use commands." "Print help for unstable internal-use commands."
end end
sig { void }
def run def run
max_command_len = Cmd.commands.map(&:length).max max_command_len = Cmd.commands.map(&:length).max
puts "Unstable Internal-use Commands:\n\n" puts "Unstable Internal-use Commands:\n\n"

View File

@ -9,6 +9,8 @@ module Cask
# #
# @api private # @api private
class InternalStanza < AbstractInternalCommand class InternalStanza < AbstractInternalCommand
extend T::Sig
# Syntax # Syntax
# #
# brew cask _stanza <stanza_name> [ --quiet ] [ --table | --yaml ] [ <cask_token> ... ] # brew cask _stanza <stanza_name> [ --quiet ] [ --table | --yaml ] [ <cask_token> ... ]
@ -24,14 +26,17 @@ module Cask
(DSL::ORDINARY_ARTIFACT_CLASSES.map(&:dsl_key) + (DSL::ORDINARY_ARTIFACT_CLASSES.map(&:dsl_key) +
DSL::ARTIFACT_BLOCK_CLASSES.map(&:dsl_key)).freeze DSL::ARTIFACT_BLOCK_CLASSES.map(&:dsl_key)).freeze
sig { override.returns(T.nilable(T.any(Integer, Symbol))) }
def self.min_named def self.min_named
1 1
end end
sig { returns(String) }
def self.banner_args def self.banner_args
" <stanza_name> [<cask>]" " <stanza_name> [<cask>]"
end end
sig { returns(String) }
def self.description def self.description
<<~EOS <<~EOS
Extract and render a specific stanza for the given <cask>. Extract and render a specific stanza for the given <cask>.
@ -80,6 +85,7 @@ module Cask
EOS EOS
end end
sig { void }
def run def run
if ARTIFACTS.include?(stanza) if ARTIFACTS.include?(stanza)
artifact_name = stanza artifact_name = stanza

View File

@ -9,6 +9,9 @@ module Cask
# #
# @api private # @api private
class List < AbstractCommand class List < AbstractCommand
extend T::Sig
sig { returns(String) }
def self.description def self.description
"Lists installed casks or the casks provided in the arguments." "Lists installed casks or the casks provided in the arguments."
end end
@ -26,6 +29,7 @@ module Cask
end end
end end
sig { void }
def run def run
self.class.list_casks( self.class.list_casks(
*casks, *casks,

View File

@ -7,6 +7,9 @@ module Cask
# #
# @api private # @api private
class Outdated < AbstractCommand class Outdated < AbstractCommand
extend T::Sig
sig { returns(String) }
def self.description def self.description
"List the outdated installed casks." "List the outdated installed casks."
end end
@ -20,6 +23,7 @@ module Cask
end end
end end
sig { void }
def run def run
outdated_casks = casks(alternative: -> { Caskroom.casks(config: Config.from_args(args)) }).select do |cask| outdated_casks = casks(alternative: -> { Caskroom.casks(config: Config.from_args(args)) }).select do |cask|
odebug "Checking update info of Cask #{cask}" odebug "Checking update info of Cask #{cask}"

View File

@ -7,10 +7,14 @@ module Cask
# #
# @api private # @api private
class Reinstall < Install class Reinstall < Install
extend T::Sig
sig { returns(String) }
def self.description def self.description
"Reinstalls the given <cask>." "Reinstalls the given <cask>."
end end
sig { void }
def run def run
self.class.reinstall_casks( self.class.reinstall_casks(
*casks, *casks,

View File

@ -10,6 +10,9 @@ module Cask
# #
# @api private # @api private
class Style < AbstractCommand class Style < AbstractCommand
extend T::Sig
sig { returns(String) }
def self.description def self.description
"Checks style of the given <cask> using RuboCop." "Checks style of the given <cask> using RuboCop."
end end
@ -21,6 +24,7 @@ module Cask
end end
end end
sig { void }
def run def run
success = Homebrew::Style.check_style_and_print( success = Homebrew::Style.check_style_and_print(
cask_paths, cask_paths,

View File

@ -7,10 +7,14 @@ module Cask
# #
# @api private # @api private
class Uninstall < AbstractCommand class Uninstall < AbstractCommand
extend T::Sig
sig { override.returns(T.nilable(T.any(Integer, Symbol))) }
def self.min_named def self.min_named
:cask :cask
end end
sig { returns(String) }
def self.description def self.description
"Uninstalls the given <cask>." "Uninstalls the given <cask>."
end end
@ -23,6 +27,7 @@ module Cask
end end
end end
sig { void }
def run def run
self.class.uninstall_casks( self.class.uninstall_casks(
*casks, *casks,

View File

@ -10,6 +10,9 @@ module Cask
# #
# @api private # @api private
class Upgrade < AbstractCommand class Upgrade < AbstractCommand
extend T::Sig
sig { returns(String) }
def self.description def self.description
"Upgrades all outdated casks or the specified casks." "Upgrades all outdated casks or the specified casks."
end end
@ -36,6 +39,7 @@ module Cask
end end
end end
sig { void }
def run def run
verbose = ($stdout.tty? || args.verbose?) && !args.quiet? verbose = ($stdout.tty? || args.verbose?) && !args.quiet?
self.class.upgrade_casks( self.class.upgrade_casks(

View File

@ -7,10 +7,14 @@ module Cask
# #
# @api private # @api private
class Zap < AbstractCommand class Zap < AbstractCommand
extend T::Sig
sig { override.returns(T.nilable(T.any(Integer, Symbol))) }
def self.min_named def self.min_named
:cask :cask
end end
sig { returns(String) }
def self.description def self.description
<<~EOS <<~EOS
Zaps all files associated with the given <cask>. Implicitly also performs all actions associated with `uninstall`. Zaps all files associated with the given <cask>. Implicitly also performs all actions associated with `uninstall`.
@ -26,6 +30,7 @@ module Cask
end end
end end
sig { void }
def run def run
require "cask/installer" require "cask/installer"

View File

@ -1,4 +1,4 @@
# typed: true # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
module Cask module Cask
@ -6,6 +6,9 @@ module Cask
# #
# @api private # @api private
module Denylist module Denylist
extend T::Sig
sig { params(name: String).returns(T.nilable(String)) }
def self.reason(name) def self.reason(name)
case name case name
when /^adobe-(after|illustrator|indesign|photoshop|premiere)/ when /^adobe-(after|illustrator|indesign|photoshop|premiere)/

View File

@ -7,6 +7,8 @@ module Cask
# #
# @api private # @api private
class Version < ::String class Version < ::String
extend T::Sig
DIVIDERS = { DIVIDERS = {
"." => :dots, "." => :dots,
"-" => :hyphens, "-" => :hyphens,
@ -62,6 +64,7 @@ module Cask
attr_reader :raw_version attr_reader :raw_version
sig { params(raw_version: T.nilable(T.any(String, Symbol))).void }
def initialize(raw_version) def initialize(raw_version)
@raw_version = raw_version @raw_version = raw_version
super(raw_version.to_s) super(raw_version.to_s)
@ -73,6 +76,7 @@ module Cask
raw_version.scan(INVALID_CHARACTERS) raw_version.scan(INVALID_CHARACTERS)
end end
sig { returns(T::Boolean) }
def unstable? def unstable?
return false if latest? return false if latest?
@ -84,6 +88,7 @@ module Cask
false false
end end
sig { returns(T::Boolean) }
def latest? def latest?
to_s == "latest" to_s == "latest"
end end
@ -134,6 +139,7 @@ module Cask
private private
sig { returns(T.self_type) }
def version def version
return self if empty? || latest? return self if empty? || latest?

View File

@ -11,12 +11,15 @@ module Cask
# #
# @api private # @api private
class MultipleCaskErrors < CaskError class MultipleCaskErrors < CaskError
extend T::Sig
def initialize(errors) def initialize(errors)
super() super()
@errors = errors @errors = errors
end end
sig { returns(String) }
def to_s def to_s
<<~EOS <<~EOS
Problems with multiple casks: Problems with multiple casks:
@ -29,12 +32,18 @@ module Cask
# #
# @api private # @api private
class AbstractCaskErrorWithToken < CaskError class AbstractCaskErrorWithToken < CaskError
attr_reader :token, :reason extend T::Sig
sig { returns(String) }
attr_reader :token
sig { returns(String) }
attr_reader :reason
def initialize(token, reason = nil) def initialize(token, reason = nil)
super() super()
@token = token @token = token.to_s
@reason = reason.to_s @reason = reason.to_s
end end
end end
@ -43,6 +52,9 @@ module Cask
# #
# @api private # @api private
class CaskNotInstalledError < AbstractCaskErrorWithToken class CaskNotInstalledError < AbstractCaskErrorWithToken
extend T::Sig
sig { returns(String) }
def to_s def to_s
"Cask '#{token}' is not installed." "Cask '#{token}' is not installed."
end end
@ -52,6 +64,8 @@ module Cask
# #
# @api private # @api private
class CaskConflictError < AbstractCaskErrorWithToken class CaskConflictError < AbstractCaskErrorWithToken
extend T::Sig
attr_reader :conflicting_cask attr_reader :conflicting_cask
def initialize(token, conflicting_cask) def initialize(token, conflicting_cask)
@ -59,6 +73,7 @@ module Cask
@conflicting_cask = conflicting_cask @conflicting_cask = conflicting_cask
end end
sig { returns(String) }
def to_s def to_s
"Cask '#{token}' conflicts with '#{conflicting_cask}'." "Cask '#{token}' conflicts with '#{conflicting_cask}'."
end end
@ -68,6 +83,9 @@ module Cask
# #
# @api private # @api private
class CaskUnavailableError < AbstractCaskErrorWithToken class CaskUnavailableError < AbstractCaskErrorWithToken
extend T::Sig
sig { returns(String) }
def to_s def to_s
"Cask '#{token}' is unavailable#{reason.empty? ? "." : ": #{reason}"}" "Cask '#{token}' is unavailable#{reason.empty? ? "." : ": #{reason}"}"
end end
@ -77,6 +95,9 @@ module Cask
# #
# @api private # @api private
class CaskUnreadableError < CaskUnavailableError class CaskUnreadableError < CaskUnavailableError
extend T::Sig
sig { returns(String) }
def to_s def to_s
"Cask '#{token}' is unreadable#{reason.empty? ? "." : ": #{reason}"}" "Cask '#{token}' is unreadable#{reason.empty? ? "." : ": #{reason}"}"
end end
@ -86,6 +107,9 @@ module Cask
# #
# @api private # @api private
class CaskAlreadyCreatedError < AbstractCaskErrorWithToken class CaskAlreadyCreatedError < AbstractCaskErrorWithToken
extend T::Sig
sig { returns(String) }
def to_s def to_s
%Q(Cask '#{token}' already exists. Run #{Formatter.identifier("brew cask edit #{token}")} to edit it.) %Q(Cask '#{token}' already exists. Run #{Formatter.identifier("brew cask edit #{token}")} to edit it.)
end end
@ -95,6 +119,9 @@ module Cask
# #
# @api private # @api private
class CaskAlreadyInstalledError < AbstractCaskErrorWithToken class CaskAlreadyInstalledError < AbstractCaskErrorWithToken
extend T::Sig
sig { returns(String) }
def to_s def to_s
<<~EOS <<~EOS
Cask '#{token}' is already installed. Cask '#{token}' is already installed.
@ -109,6 +136,9 @@ module Cask
# #
# @api private # @api private
class CaskX11DependencyError < AbstractCaskErrorWithToken class CaskX11DependencyError < AbstractCaskErrorWithToken
extend T::Sig
sig { returns(String) }
def to_s def to_s
<<~EOS <<~EOS
Cask '#{token}' requires XQuartz/X11, which can be installed using Homebrew Cask by running: Cask '#{token}' requires XQuartz/X11, which can be installed using Homebrew Cask by running:
@ -124,6 +154,9 @@ module Cask
# #
# @api private # @api private
class CaskCyclicDependencyError < AbstractCaskErrorWithToken class CaskCyclicDependencyError < AbstractCaskErrorWithToken
extend T::Sig
sig { returns(String) }
def to_s def to_s
"Cask '#{token}' includes cyclic dependencies on other Casks#{reason.empty? ? "." : ": #{reason}"}" "Cask '#{token}' includes cyclic dependencies on other Casks#{reason.empty? ? "." : ": #{reason}"}"
end end
@ -133,6 +166,9 @@ module Cask
# #
# @api private # @api private
class CaskSelfReferencingDependencyError < CaskCyclicDependencyError class CaskSelfReferencingDependencyError < CaskCyclicDependencyError
extend T::Sig
sig { returns(String) }
def to_s def to_s
"Cask '#{token}' depends on itself." "Cask '#{token}' depends on itself."
end end
@ -142,6 +178,9 @@ module Cask
# #
# @api private # @api private
class CaskUnspecifiedError < CaskError class CaskUnspecifiedError < CaskError
extend T::Sig
sig { returns(String) }
def to_s def to_s
"This command requires a Cask token." "This command requires a Cask token."
end end
@ -151,6 +190,9 @@ module Cask
# #
# @api private # @api private
class CaskInvalidError < AbstractCaskErrorWithToken class CaskInvalidError < AbstractCaskErrorWithToken
extend T::Sig
sig { returns(String) }
def to_s def to_s
"Cask '#{token}' definition is invalid#{reason.empty? ? "." : ": #{reason}"}" "Cask '#{token}' definition is invalid#{reason.empty? ? "." : ": #{reason}"}"
end end
@ -182,6 +224,9 @@ module Cask
# #
# @api private # @api private
class CaskSha256MissingError < CaskSha256Error class CaskSha256MissingError < CaskSha256Error
extend T::Sig
sig { returns(String) }
def to_s def to_s
<<~EOS <<~EOS
Cask '#{token}' requires a checksum: Cask '#{token}' requires a checksum:
@ -194,6 +239,8 @@ module Cask
# #
# @api private # @api private
class CaskSha256MismatchError < CaskSha256Error class CaskSha256MismatchError < CaskSha256Error
extend T::Sig
attr_reader :path attr_reader :path
def initialize(token, expected, actual, path) def initialize(token, expected, actual, path)
@ -201,6 +248,7 @@ module Cask
@path = path @path = path
end end
sig { returns(String) }
def to_s def to_s
<<~EOS <<~EOS
Checksum for Cask '#{token}' does not match. Checksum for Cask '#{token}' does not match.
@ -218,6 +266,9 @@ module Cask
# #
# @api private # @api private
class CaskNoShasumError < CaskSha256Error class CaskNoShasumError < CaskSha256Error
extend T::Sig
sig { returns(String) }
def to_s def to_s
<<~EOS <<~EOS
Cask '#{token}' does not have a sha256 checksum defined and was not installed. Cask '#{token}' does not have a sha256 checksum defined and was not installed.
@ -230,6 +281,8 @@ module Cask
# #
# @api private # @api private
class CaskQuarantineError < CaskError class CaskQuarantineError < CaskError
extend T::Sig
attr_reader :path, :reason attr_reader :path, :reason
def initialize(path, reason) def initialize(path, reason)
@ -239,6 +292,7 @@ module Cask
@reason = reason @reason = reason
end end
sig { returns(String) }
def to_s def to_s
s = +"Failed to quarantine #{path}." s = +"Failed to quarantine #{path}."
@ -256,6 +310,9 @@ module Cask
# #
# @api private # @api private
class CaskQuarantinePropagationError < CaskQuarantineError class CaskQuarantinePropagationError < CaskQuarantineError
extend T::Sig
sig { returns(String) }
def to_s def to_s
s = +"Failed to quarantine one or more files within #{path}." s = +"Failed to quarantine one or more files within #{path}."
@ -273,6 +330,9 @@ module Cask
# #
# @api private # @api private
class CaskQuarantineReleaseError < CaskQuarantineError class CaskQuarantineReleaseError < CaskQuarantineError
extend T::Sig
sig { returns(String) }
def to_s def to_s
s = +"Failed to release #{path} from quarantine." s = +"Failed to release #{path} from quarantine."

View File

@ -18,6 +18,8 @@ module Cask
# #
# @api private # @api private
class Installer class Installer
extend T::Sig
extend Predicable extend Predicable
# TODO: it is unwise for Cask::Staged to be a module, when we are # TODO: it is unwise for Cask::Staged to be a module, when we are
# dealing with both staged and unstaged casks here. This should # dealing with both staged and unstaged casks here. This should
@ -142,6 +144,7 @@ module Cask
Installer.new(installed_cask, binaries: binaries?, verbose: verbose?, force: true, upgrade: upgrade?).uninstall Installer.new(installed_cask, binaries: binaries?, verbose: verbose?, force: true, upgrade: upgrade?).uninstall
end end
sig { returns(String) }
def summary def summary
s = +"" s = +""
s << "#{Homebrew::EnvConfig.install_badge} " unless Homebrew::EnvConfig.no_emoji? s << "#{Homebrew::EnvConfig.install_badge} " unless Homebrew::EnvConfig.no_emoji?

View File

@ -9,6 +9,8 @@ module Cask
# #
# @api private # @api private
module Quarantine module Quarantine
extend T::Sig
module_function module_function
QUARANTINE_ATTRIBUTE = "com.apple.quarantine" QUARANTINE_ATTRIBUTE = "com.apple.quarantine"
@ -25,6 +27,7 @@ module Cask
end end
private :xattr private :xattr
sig { returns(Symbol) }
def check_quarantine_support def check_quarantine_support
odebug "Checking quarantine support" odebug "Checking quarantine support"

View File

@ -13,6 +13,8 @@ module Cask
# #
# @api private # @api private
module Utils module Utils
extend T::Sig
def self.gain_permissions_remove(path, command: SystemCommand) def self.gain_permissions_remove(path, command: SystemCommand)
if path.respond_to?(:rmtree) && path.exist? if path.respond_to?(:rmtree) && path.exist?
gain_permissions(path, ["-R"], command) do |p| gain_permissions(path, ["-R"], command) do |p|
@ -72,10 +74,12 @@ module Cask
end end
end end
sig { params(path: Pathname).returns(T::Boolean) }
def self.path_occupied?(path) def self.path_occupied?(path)
File.exist?(path) || File.symlink?(path) path.exist? || path.symlink?
end end
sig { returns(String) }
def self.error_message_with_suggestions def self.error_message_with_suggestions
<<~EOS <<~EOS
Follow the instructions here: Follow the instructions here:

View File

@ -7,11 +7,14 @@ require "ostruct"
module Homebrew module Homebrew
module CLI module CLI
class Args < OpenStruct class Args < OpenStruct
extend T::Sig
attr_reader :options_only, :flags_only attr_reader :options_only, :flags_only
# undefine tap to allow --tap argument # undefine tap to allow --tap argument
undef tap undef tap
sig { void }
def initialize def initialize
super() super()
@ -131,6 +134,7 @@ module Homebrew
flag_with_value.delete_prefix(arg_prefix) flag_with_value.delete_prefix(arg_prefix)
end end
sig { returns(Context::ContextStruct) }
def context def context
Context::ContextStruct.new(debug: debug?, quiet: quiet?, verbose: verbose?) Context::ContextStruct.new(debug: debug?, quiet: quiet?, verbose: verbose?)
end end

View File

@ -14,6 +14,8 @@ OPTION_DESC_WIDTH = 43
module Homebrew module Homebrew
module CLI module CLI
class Parser class Parser
extend T::Sig
attr_reader :processed_options, :hide_from_man_page attr_reader :processed_options, :hide_from_man_page
def self.from_cmd_path(cmd_path) def self.from_cmd_path(cmd_path)
@ -94,6 +96,7 @@ module Homebrew
] ]
end end
sig { returns(T::Array[[String, String, String]]) }
def self.global_options def self.global_options
[ [
["-d", "--debug", "Display any debugging information."], ["-d", "--debug", "Display any debugging information."],
@ -103,6 +106,9 @@ module Homebrew
] ]
end end
# FIXME: Block should be `T.nilable(T.proc.bind(Parser).void)`.
# See https://github.com/sorbet/sorbet/issues/498.
sig { params(block: T.proc.bind(Parser).void).void.checked(:never) }
def initialize(&block) def initialize(&block)
@parser = OptionParser.new @parser = OptionParser.new
@ -331,6 +337,7 @@ module Homebrew
end end
end end
sig { void }
def formula_options def formula_options
@formula_options = true @formula_options = true
end end
@ -367,6 +374,7 @@ module Homebrew
end end
end end
sig { void }
def hide_from_man_page! def hide_from_man_page!
@hide_from_man_page = true @hide_from_man_page = true
end end
@ -454,7 +462,8 @@ module Homebrew
end end
def check_named_args(args) def check_named_args(args)
min_exception = case @min_named_type exception = if @min_named_args && args.size < @min_named_args
case @min_named_type
when :cask when :cask
Cask::CaskUnspecifiedError Cask::CaskUnspecifiedError
when :formula when :formula
@ -466,8 +475,11 @@ module Homebrew
else else
MinNamedArgumentsError.new(@min_named_args) MinNamedArgumentsError.new(@min_named_args)
end end
raise min_exception if @min_named_args && args.size < @min_named_args elsif @max_named_args && args.size > @max_named_args
raise MaxNamedArgumentsError, @max_named_args if @max_named_args && args.size > @max_named_args MaxNamedArgumentsError.new(@max_named_args)
end
raise exception if exception
end end
def process_option(*args) def process_option(*args)
@ -535,6 +547,9 @@ module Homebrew
end end
class MaxNamedArgumentsError < UsageError class MaxNamedArgumentsError < UsageError
extend T::Sig
sig { params(maximum: Integer).void }
def initialize(maximum) def initialize(maximum)
super case maximum super case maximum
when 0 when 0
@ -546,6 +561,9 @@ module Homebrew
end end
class MinNamedArgumentsError < UsageError class MinNamedArgumentsError < UsageError
extend T::Sig
sig { params(minimum: Integer).void }
def initialize(minimum) def initialize(minimum)
super "This command requires at least #{minimum} named #{"argument".pluralize(minimum)}." super "This command requires at least #{minimum} named #{"argument".pluralize(minimum)}."
end end

View File

@ -6,10 +6,13 @@ require "cli/parser"
require "cask/download" require "cask/download"
module Homebrew module Homebrew
extend T::Sig
extend Fetch extend Fetch
module_function module_function
sig { returns(CLI::Parser) }
def __cache_args def __cache_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -1,9 +1,12 @@
# typed: false # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def __caskroom_args def __caskroom_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS
@ -17,6 +20,7 @@ module Homebrew
end end
end end
sig { void }
def __caskroom def __caskroom
args = __caskroom_args.parse args = __caskroom_args.parse

View File

@ -7,8 +7,11 @@ require "utils/shell"
require "cli/parser" require "cli/parser"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def __env_args def __env_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -4,8 +4,11 @@
require "cli/parser" require "cli/parser"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def __prefix_args def __prefix_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -4,8 +4,11 @@
require "cli/parser" require "cli/parser"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def __repository_args def __repository_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -4,8 +4,11 @@
require "cli/parser" require "cli/parser"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def __version_args def __version_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -4,8 +4,11 @@
require "cli/parser" require "cli/parser"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def analytics_args def analytics_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -5,8 +5,11 @@ require "cleanup"
require "cli/parser" require "cli/parser"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def cleanup_args def cleanup_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
days = Homebrew::EnvConfig::ENVS[:HOMEBREW_CLEANUP_MAX_AGE_DAYS][:default] days = Homebrew::EnvConfig::ENVS[:HOMEBREW_CLEANUP_MAX_AGE_DAYS][:default]

View File

@ -4,8 +4,11 @@
require "cli/parser" require "cli/parser"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def commands_args def commands_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -5,8 +5,11 @@ require "system_config"
require "cli/parser" require "cli/parser"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def config_args def config_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -8,10 +8,13 @@ require "cask/caskroom"
require "dependencies_helpers" require "dependencies_helpers"
module Homebrew module Homebrew
extend T::Sig
extend DependenciesHelpers extend DependenciesHelpers
module_function module_function
sig { returns(CLI::Parser) }
def deps_args def deps_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -7,10 +7,13 @@ require "description_cache_store"
require "cli/parser" require "cli/parser"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
extend Search extend Search
sig { returns(CLI::Parser) }
def desc_args def desc_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -6,8 +6,11 @@ require "cli/parser"
require "cask/caskroom" require "cask/caskroom"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def doctor_args def doctor_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -6,10 +6,13 @@ require "fetch"
require "cli/parser" require "cli/parser"
module Homebrew module Homebrew
extend T::Sig
extend Fetch extend Fetch
module_function module_function
sig { returns(CLI::Parser) }
def fetch_args def fetch_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -9,10 +9,13 @@ require "socket"
require "cli/parser" require "cli/parser"
module Homebrew module Homebrew
extend T::Sig
extend Install extend Install
module_function module_function
sig { returns(CLI::Parser) }
def gist_logs_args def gist_logs_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -4,8 +4,11 @@
require "cli/parser" require "cli/parser"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def home_args def home_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -13,12 +13,15 @@ require "utils/spdx"
require "deprecate_disable" require "deprecate_disable"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
VALID_DAYS = %w[30 90 365].freeze VALID_DAYS = %w[30 90 365].freeze
VALID_FORMULA_CATEGORIES = %w[install install-on-request build-error].freeze VALID_FORMULA_CATEGORIES = %w[install install-on-request build-error].freeze
VALID_CATEGORIES = (VALID_FORMULA_CATEGORIES + %w[cask-install os-version]).freeze VALID_CATEGORIES = (VALID_FORMULA_CATEGORIES + %w[cask-install os-version]).freeze
sig { returns(CLI::Parser) }
def info_args def info_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -14,10 +14,13 @@ require "cli/parser"
require "upgrade" require "upgrade"
module Homebrew module Homebrew
extend T::Sig
extend Search extend Search
module_function module_function
sig { returns(CLI::Parser) }
def install_args def install_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -5,8 +5,11 @@ require "formula"
require "cli/parser" require "cli/parser"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def leaves_args def leaves_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -7,8 +7,11 @@ require "cli/parser"
require "unlink" require "unlink"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def link_args def link_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -7,8 +7,11 @@ require "cli/parser"
require "cask/cmd" require "cask/cmd"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def list_args def list_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -5,8 +5,11 @@ require "formula"
require "cli/parser" require "cli/parser"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def log_args def log_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -5,8 +5,11 @@ require "migrator"
require "cli/parser" require "cli/parser"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def migrate_args def migrate_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -7,8 +7,11 @@ require "diagnostic"
require "cli/parser" require "cli/parser"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def missing_args def missing_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -7,8 +7,11 @@ require "cli/parser"
require "commands" require "commands"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def options_args def options_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -8,8 +8,11 @@ require "cask/cmd"
require "cask/caskroom" require "cask/caskroom"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def outdated_args def outdated_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -5,8 +5,11 @@ require "formula"
require "cli/parser" require "cli/parser"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def pin_args def pin_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -6,8 +6,11 @@ require "formula_installer"
require "cli/parser" require "cli/parser"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def postinstall_args def postinstall_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -5,8 +5,11 @@ require "readall"
require "cli/parser" require "cli/parser"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def readall_args def readall_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -14,8 +14,11 @@ require "cask/macos"
require "upgrade" require "upgrade"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def reinstall_args def reinstall_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -8,6 +8,8 @@ require "cli/parser"
require "search" require "search"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
extend Search extend Search
@ -25,6 +27,7 @@ module Homebrew
}, },
}.freeze }.freeze
sig { returns(CLI::Parser) }
def search_args def search_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -6,8 +6,11 @@ require "keg"
require "cli/parser" require "cli/parser"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def switch_args def switch_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -4,8 +4,11 @@
require "cli/parser" require "cli/parser"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def tap_info_args def tap_info_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -4,8 +4,11 @@
require "cli/parser" require "cli/parser"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def tap_args def tap_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -11,8 +11,11 @@ require "cask/cask_loader"
require "uninstall" require "uninstall"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def uninstall_args def uninstall_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -6,8 +6,11 @@ require "cli/parser"
require "unlink" require "unlink"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def unlink_args def unlink_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -5,8 +5,11 @@ require "formula"
require "cli/parser" require "cli/parser"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def unpin_args def unpin_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -4,8 +4,11 @@
require "cli/parser" require "cli/parser"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def untap_args def untap_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -10,6 +10,8 @@ require "description_cache_store"
require "cli/parser" require "cli/parser"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
def update_preinstall_header(args:) def update_preinstall_header(args:)
@ -19,6 +21,7 @@ module Homebrew
end end
end end
sig { returns(CLI::Parser) }
def update_report_args def update_report_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS
@ -413,10 +416,13 @@ class Reporter
end end
class ReporterHub class ReporterHub
extend T::Sig
extend Forwardable extend Forwardable
attr_reader :reporters attr_reader :reporters
sig { void }
def initialize def initialize
@hash = {} @hash = {}
@reporters = [] @reporters = []

View File

@ -10,8 +10,11 @@ require "cask/utils"
require "cask/macos" require "cask/macos"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def upgrade_args def upgrade_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -11,10 +11,13 @@ require "cask/caskroom"
require "dependencies_helpers" require "dependencies_helpers"
module Homebrew module Homebrew
extend T::Sig
extend DependenciesHelpers extend DependenciesHelpers
module_function module_function
sig { returns(CLI::Parser) }
def uses_args def uses_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -4,28 +4,36 @@
raise "HOMEBREW_BREW_FILE was not exported! Please call bin/brew directly!" unless ENV["HOMEBREW_BREW_FILE"] raise "HOMEBREW_BREW_FILE was not exported! Please call bin/brew directly!" unless ENV["HOMEBREW_BREW_FILE"]
# Path to `bin/brew` main executable in `HOMEBREW_PREFIX` # Path to `bin/brew` main executable in `HOMEBREW_PREFIX`
HOMEBREW_BREW_FILE = Pathname.new(ENV["HOMEBREW_BREW_FILE"]).freeze HOMEBREW_BREW_FILE = Pathname(ENV["HOMEBREW_BREW_FILE"]).freeze
class MissingEnvironmentVariables < RuntimeError; end class MissingEnvironmentVariables < RuntimeError; end
def get_env_or_raise(env) # Helper module for getting environment variables which must be set.
#
# @api private
module EnvVar
extend T::Sig
sig { params(env: String).returns(String) }
def self.[](env)
raise MissingEnvironmentVariables, "#{env} was not exported!" unless ENV[env] raise MissingEnvironmentVariables, "#{env} was not exported!" unless ENV[env]
ENV[env] ENV.fetch(env)
end
end end
require "extend/git_repository" require "extend/git_repository"
# Where we link under # Where we link under
HOMEBREW_PREFIX = Pathname.new(get_env_or_raise("HOMEBREW_PREFIX")).freeze HOMEBREW_PREFIX = Pathname(EnvVar["HOMEBREW_PREFIX"]).freeze
# Where `.git` is found # Where `.git` is found
HOMEBREW_REPOSITORY = Pathname.new(get_env_or_raise("HOMEBREW_REPOSITORY")) HOMEBREW_REPOSITORY = Pathname(EnvVar["HOMEBREW_REPOSITORY"])
.extend(GitRepositoryExtension) .extend(GitRepositoryExtension)
.freeze .freeze
# Where we store most of Homebrew, taps, and various metadata # Where we store most of Homebrew, taps, and various metadata
HOMEBREW_LIBRARY = Pathname.new(get_env_or_raise("HOMEBREW_LIBRARY")).freeze HOMEBREW_LIBRARY = Pathname(EnvVar["HOMEBREW_LIBRARY"]).freeze
# Where shim scripts for various build and SCM tools are stored # Where shim scripts for various build and SCM tools are stored
HOMEBREW_SHIMS_PATH = (HOMEBREW_LIBRARY/"Homebrew/shims").freeze HOMEBREW_SHIMS_PATH = (HOMEBREW_LIBRARY/"Homebrew/shims").freeze
@ -43,19 +51,19 @@ HOMEBREW_PINNED_KEGS = (HOMEBREW_PREFIX/"var/homebrew/pinned").freeze
HOMEBREW_LOCKS = (HOMEBREW_PREFIX/"var/homebrew/locks").freeze HOMEBREW_LOCKS = (HOMEBREW_PREFIX/"var/homebrew/locks").freeze
# Where we store built products # Where we store built products
HOMEBREW_CELLAR = Pathname.new(get_env_or_raise("HOMEBREW_CELLAR")).freeze HOMEBREW_CELLAR = Pathname(EnvVar["HOMEBREW_CELLAR"]).freeze
# Where downloads (bottles, source tarballs, etc.) are cached # Where downloads (bottles, source tarballs, etc.) are cached
HOMEBREW_CACHE = Pathname.new(get_env_or_raise("HOMEBREW_CACHE")).freeze HOMEBREW_CACHE = Pathname(EnvVar["HOMEBREW_CACHE"]).freeze
# Where brews installed via URL are cached # Where brews installed via URL are cached
HOMEBREW_CACHE_FORMULA = (HOMEBREW_CACHE/"Formula").freeze HOMEBREW_CACHE_FORMULA = (HOMEBREW_CACHE/"Formula").freeze
# Where build, postinstall, and test logs of formulae are written to # Where build, postinstall, and test logs of formulae are written to
HOMEBREW_LOGS = Pathname.new(get_env_or_raise("HOMEBREW_LOGS")).expand_path.freeze HOMEBREW_LOGS = Pathname(EnvVar["HOMEBREW_LOGS"]).expand_path.freeze
# Must use `/tmp` instead of `TMPDIR` because long paths break Unix domain sockets # Must use `/tmp` instead of `TMPDIR` because long paths break Unix domain sockets
HOMEBREW_TEMP = Pathname.new(get_env_or_raise("HOMEBREW_TEMP")).yield_self do |tmp| HOMEBREW_TEMP = Pathname(EnvVar["HOMEBREW_TEMP"]).yield_self do |tmp|
tmp.mkpath unless tmp.exist? tmp.mkpath unless tmp.exist?
tmp.realpath tmp.realpath
end.freeze end.freeze

View File

@ -5,6 +5,8 @@ require "compilers"
# Combination of C++ standard library and compiler. # Combination of C++ standard library and compiler.
class CxxStdlib class CxxStdlib
extend T::Sig
include CompilerConstants include CompilerConstants
# Error for when a formula's dependency was built with a different C++ standard library. # Error for when a formula's dependency was built with a different C++ standard library.
@ -72,6 +74,7 @@ class CxxStdlib
type.to_s.gsub(/cxx$/, "c++") type.to_s.gsub(/cxx$/, "c++")
end end
sig { returns(String) }
def inspect def inspect
"#<#{self.class.name}: #{compiler} #{type}>" "#<#{self.class.name}: #{compiler} #{type}>"
end end

View File

@ -41,10 +41,13 @@ module Debrew
# Module for displaying a debugging menu. # Module for displaying a debugging menu.
class Menu class Menu
extend T::Sig
Entry = Struct.new(:name, :action) Entry = Struct.new(:name, :action)
attr_accessor :prompt, :entries attr_accessor :prompt, :entries
sig { void }
def initialize def initialize
@entries = [] @entries = []
end end

View File

@ -8,6 +8,8 @@ require "cask_dependent"
# #
# @api private # @api private
class Dependencies < SimpleDelegator class Dependencies < SimpleDelegator
extend T::Sig
def initialize(*args) def initialize(*args)
super(args) super(args)
end end
@ -34,6 +36,7 @@ class Dependencies < SimpleDelegator
build + required + recommended build + required + recommended
end end
sig { returns(String) }
def inspect def inspect
"#<#{self.class.name}: #{to_a}>" "#<#{self.class.name}: #{to_a}>"
end end
@ -43,6 +46,8 @@ end
# #
# @api private # @api private
class Requirements < SimpleDelegator class Requirements < SimpleDelegator
extend T::Sig
def initialize(*args) def initialize(*args)
super(Set.new(args)) super(Set.new(args))
end end
@ -59,6 +64,7 @@ class Requirements < SimpleDelegator
self self
end end
sig { returns(String) }
def inspect def inspect
"#<#{self.class.name}: {#{to_a.join(", ")}}>" "#<#{self.class.name}: {#{to_a.join(", ")}}>"
end end

View File

@ -7,6 +7,8 @@ require "dependable"
# #
# @api private # @api private
class Dependency class Dependency
extend T::Sig
extend Forwardable extend Forwardable
include Dependable include Dependable
@ -64,6 +66,7 @@ class Dependency
env_proc&.call env_proc&.call
end end
sig { returns(String) }
def inspect def inspect
"#<#{self.class.name}: #{name.inspect} #{tags.inspect}>" "#<#{self.class.name}: #{name.inspect} #{tags.inspect}>"
end end
@ -78,6 +81,8 @@ class Dependency
end end
class << self class << self
extend T::Sig
# Expand the dependencies of each dependent recursively, optionally yielding # Expand the dependencies of each dependent recursively, optionally yielding
# `[dependent, dep]` pairs to allow callers to apply arbitrary filters to # `[dependent, dep]` pairs to allow callers to apply arbitrary filters to
# the list. # the list.
@ -126,16 +131,19 @@ class Dependency
end end
# Prune a dependency and its dependencies recursively. # Prune a dependency and its dependencies recursively.
sig { void }
def prune def prune
throw(:action, :prune) throw(:action, :prune)
end end
# Prune a single dependency but do not prune its dependencies. # Prune a single dependency but do not prune its dependencies.
sig { void }
def skip def skip
throw(:action, :skip) throw(:action, :skip)
end end
# Keep a dependency, but prune its dependencies. # Keep a dependency, but prune its dependencies.
sig { void }
def keep_but_prune_recursive_deps def keep_but_prune_recursive_deps
throw(:action, :keep_but_prune_recursive_deps) throw(:action, :keep_but_prune_recursive_deps)
end end

View File

@ -18,10 +18,13 @@ require "extend/cachable"
# This class is used by `depends_on` in the formula DSL to turn dependency # This class is used by `depends_on` in the formula DSL to turn dependency
# specifications into the proper kinds of dependencies and requirements. # specifications into the proper kinds of dependencies and requirements.
class DependencyCollector class DependencyCollector
extend T::Sig
extend Cachable extend Cachable
attr_reader :deps, :requirements attr_reader :deps, :requirements
sig { void }
def initialize def initialize
@deps = Dependencies.new @deps = Dependencies.new
@requirements = Requirements.new @requirements = Requirements.new

View File

@ -18,8 +18,11 @@ require "cli/parser"
require "json" require "json"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def audit_args def audit_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -40,8 +40,11 @@ EOS
MAXIMUM_STRING_MATCHES = 100 MAXIMUM_STRING_MATCHES = 100
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def bottle_args def bottle_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -6,8 +6,11 @@ require "cli/parser"
require "utils/tar" require "utils/tar"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def bump_cask_pr_args def bump_cask_pr_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -7,8 +7,11 @@ require "utils/pypi"
require "utils/tar" require "utils/tar"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def bump_formula_pr_args def bump_formula_pr_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -5,8 +5,11 @@ require "formula"
require "cli/parser" require "cli/parser"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def bump_revision_args def bump_revision_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

View File

@ -4,8 +4,11 @@
require "cli/parser" require "cli/parser"
module Homebrew module Homebrew
extend T::Sig
module_function module_function
sig { returns(CLI::Parser) }
def bump_args def bump_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS

Some files were not shown because too many files have changed in this diff Show More