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
+57 -40
View File
@@ -2,54 +2,71 @@
require "formula"
require "json"
require "readall"
module Homebrew
module_function
def brewer_tap_content_info_args
Homebrew::CLI::Parser.new do
description <<~EOS
Do something. Place a description here.
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"
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
named_args [:tap]
end
end
def brewer_tap_content_info
args = brewer_tap_content_info_args.parse
formulae = []
casks = []
Tap.each do |tap|
unless args.cask?
tap.formula_files.each do |formula_file|
formulae << Formulary.factory(formula_file)
def run
begin
original_stderr = $stderr.clone
$stderr.reopen(File.new("/dev/null", "w"))
formulae = []
casks = []
Tap.each do |tap|
next if ["homebrew/core", "homebrew/cask"].include?(tap.name)
next unless valid_tap? tap
unless args.cask?
tap.formula_files.each do |formula_file|
formulae << Formulary.factory(formula_file)
end
end
unless args.formula?
tap.cask_files.each do |cask_file|
casks << Cask::CaskLoader::FromPathLoader.new(cask_file).load(config: nil)
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
unless args.formula?
tap.cask_files.each do |cask_file|
casks << Cask::CaskLoader::FromTapPathLoader.new(cask_file).load(config: nil)
private
def valid_tap?(tap)
begin
Readall.valid_tap?(tap, aliases: true)
rescue Interrupt, RuntimeError
false
end
end
end
json = {
"formulae": formulae.map(&:to_hash),
"casks": casks.map(&:to_h)
}
puts JSON.pretty_generate(json)
end
end