4 Commits

Author SHA1 Message Date
Tommaso Negri e9f09adde2 Prevent warning and errors from breaking the sync 2024-12-03 14:39:24 +01:00
Tommaso Negri d8521a0fc7 Migrate to AbstractCommand 2024-10-03 10:16:08 +02:00
Tommaso Negri 379092b344 fix: Update path loader class 2024-03-13 14:42:14 +01:00
Tommaso Negri 4d60640c8a fix: Skip homebrew/core and homebrew/cask 2024-01-09 09:51:38 +01:00
+53 -36
View File
@@ -2,54 +2,71 @@
require "formula" require "formula"
require "json" require "json"
require "readall"
module Homebrew module Homebrew
module_function module Cmd
class BrewerTapContentInfo < AbstractCommand
cmd_args do
description <<~EOS
Display the information about third-party casks and formulas.
EOS
flag "--json",
description: "Print a JSON representation. Currently the default value for <version> is `v1` for " \
"<formula>. For <formula> and <cask> use `v2`. See the docs for examples of using the " \
"JSON output: <https://docs.brew.sh/Querying-Brew>"
switch "--formula", "--formulae",
description: "Treat all named arguments as formulae."
switch "--cask", "--casks",
description: "Treat all named arguments as casks."
conflicts "--formula", "--cask"
end
def brewer_tap_content_info_args def run
Homebrew::CLI::Parser.new do begin
description <<~EOS original_stderr = $stderr.clone
Do something. Place a description here. $stderr.reopen(File.new("/dev/null", "w"))
EOS
flag "--json",
description: "Print a JSON representation. Currently the default value for <version> is `v1` for " \
"<formula>. For <formula> and <cask> use `v2`. See the docs for examples of using the " \
"JSON output: <https://docs.brew.sh/Querying-Brew>"
switch "--formula", "--formulae",
description: "Treat all named arguments as formulae."
switch "--cask", "--casks",
description: "Treat all named arguments as casks."
conflicts "--formula", "--cask"
named_args [:tap] formulae = []
end casks = []
end
def brewer_tap_content_info Tap.each do |tap|
args = brewer_tap_content_info_args.parse next if ["homebrew/core", "homebrew/cask"].include?(tap.name)
next unless valid_tap? tap
formulae = [] unless args.cask?
casks = [] tap.formula_files.each do |formula_file|
formulae << Formulary.factory(formula_file)
end
end
Tap.each do |tap| unless args.formula?
unless args.cask? tap.cask_files.each do |cask_file|
tap.formula_files.each do |formula_file| casks << Cask::CaskLoader::FromPathLoader.new(cask_file).load(config: nil)
formulae << Formulary.factory(formula_file) end
end
end
json = {
"formulae": formulae.map(&:to_hash),
"casks": casks.map(&:to_h)
}
puts JSON.pretty_generate(json)
ensure
$stderr.reopen(original_stderr)
end end
end end
unless args.formula? private
tap.cask_files.each do |cask_file|
casks << Cask::CaskLoader::FromTapPathLoader.new(cask_file).load(config: nil) def valid_tap?(tap)
begin
Readall.valid_tap?(tap, aliases: true)
rescue Interrupt, RuntimeError
false
end end
end end
end end
json = {
"formulae": formulae.map(&:to_hash),
"casks": casks.map(&:to_h)
}
puts JSON.pretty_generate(json)
end end
end end