Skip to content

Commit

Permalink
Merge pull request #16384 from apainintheneck/fix-cask-all
Browse files Browse the repository at this point in the history
Fix Cask::Cask.all bug
  • Loading branch information
MikeMcQuaid authored Dec 22, 2023
2 parents c6fbebd + b797782 commit 0b804d4
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 12 deletions.
12 changes: 7 additions & 5 deletions Library/Homebrew/cask/cask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ class Cask
attr_predicate :loaded_from_api?

# @api private
def self.all
# TODO: replace this ARGV and ENV logic with an argument, like how we do with formulae
if ARGV.exclude?("--eval-all") && !Homebrew::EnvConfig.eval_all?
def self.all(eval_all: false)
if !eval_all && !Homebrew::EnvConfig.eval_all?
raise ArgumentError, "Cask::Cask#all cannot be used without --eval-all or HOMEBREW_EVAL_ALL"
end

Tap.flat_map(&:cask_files).map do |f|
CaskLoader::FromTapPathLoader.new(f).load(config: nil)
# Load core casks from tokens so they load from the API when the core cask is not tapped.
tokens_and_files = CoreCaskTap.instance.cask_tokens
tokens_and_files += Tap.reject(&:core_cask_tap?).flat_map(&:cask_files)
tokens_and_files.map do |token_or_file|
CaskLoader.load(token_or_file)
rescue CaskUnreadableError => e
opoo e.message

Expand Down
5 changes: 3 additions & 2 deletions Library/Homebrew/cmd/deps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ def self.deps
puts_deps_tree dependents, recursive: recursive, args: args
return
elsif all
puts_deps sorted_dependents(Formula.all(eval_all: args.eval_all?) + Cask::Cask.all), recursive: recursive,
args: args
puts_deps sorted_dependents(
Formula.all(eval_all: args.eval_all?) + Cask::Cask.all(eval_all: args.eval_all?),
), recursive: recursive, args: args
return
elsif !args.no_named? && args.for_each?
puts_deps sorted_dependents(args.named.to_formulae_and_casks), recursive: recursive, args: args
Expand Down
5 changes: 4 additions & 1 deletion Library/Homebrew/cmd/info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,10 @@ def print_json(all, args:)
end
when :v2
formulae, casks = if all
[Formula.all(eval_all: args.eval_all?).sort, Cask::Cask.all.sort_by(&:full_name)]
[
Formula.all(eval_all: args.eval_all?).sort,
Cask::Cask.all(eval_all: args.eval_all?).sort_by(&:full_name),
]
elsif args.installed?
[Formula.installed.sort, Cask::Caskroom.casks.sort_by(&:full_name)]
else
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cmd/uses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def self.intersection_of_dependents(use_runtime_dependents, used_formulae, args:
deps += args.installed? ? Formula.installed : Formula.all(eval_all: args.eval_all?)
end
if show_formulae_and_casks || args.cask?
deps += args.installed? ? Cask::Caskroom.casks : Cask::Cask.all
deps += args.installed? ? Cask::Caskroom.casks : Cask::Cask.all(eval_all: args.eval_all?)
end

if args.missing?
Expand Down
3 changes: 2 additions & 1 deletion Library/Homebrew/description_cache_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def populate_if_empty!(eval_all: Homebrew::EnvConfig.eval_all?)
return unless eval_all
return unless database.empty?

Cask::Cask.all.each { |c| update!(c.full_name, [c.name.join(", "), c.desc.presence]) }
Cask::Cask.all(eval_all: eval_all)
.each { |c| update!(c.full_name, [c.name.join(", "), c.desc.presence]) }
end

# Use an update report to update the {CaskDescriptionCacheStore}.
Expand Down
5 changes: 4 additions & 1 deletion Library/Homebrew/dev-cmd/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ def self.audit
"brew audit --eval-all or HOMEBREW_EVAL_ALL"
end
no_named_args = true
[Formula.all(eval_all: args.eval_all?), Cask::Cask.all]
[
Formula.all(eval_all: args.eval_all?),
Cask::Cask.all(eval_all: args.eval_all?),
]
else
if args.named.any? { |named_arg| named_arg.end_with?(".rb") }
# This odisabled should probably stick around indefinitely,
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/livecheck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def livecheck
formulae + casks
elsif all
formulae = args.cask? ? [] : Formula.all(eval_all: args.eval_all?)
casks = args.formula? ? [] : Cask::Cask.all
casks = args.formula? ? [] : Cask::Cask.all(eval_all: args.eval_all?)
formulae + casks
elsif args.named.present?
if args.formula?
Expand Down

0 comments on commit 0b804d4

Please sign in to comment.