2 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
+57 -42
View File
@@ -2,56 +2,71 @@
require "formula" require "formula"
require "json" require "json"
require "readall"
module Homebrew module Homebrew
module_function module Cmd
class BrewerTapContentInfo < AbstractCommand
def brewer_tap_content_info_args cmd_args do
Homebrew::CLI::Parser.new do description <<~EOS
description <<~EOS Display the information about third-party casks and formulas.
Do something. Place a description here. EOS
EOS flag "--json",
flag "--json", description: "Print a JSON representation. Currently the default value for <version> is `v1` for " \
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 " \
"<formula>. For <formula> and <cask> use `v2`. See the docs for examples of using the " \ "JSON output: <https://docs.brew.sh/Querying-Brew>"
"JSON output: <https://docs.brew.sh/Querying-Brew>" switch "--formula", "--formulae",
switch "--formula", "--formulae", description: "Treat all named arguments as formulae."
description: "Treat all named arguments as formulae." switch "--cask", "--casks",
switch "--cask", "--casks", description: "Treat all named arguments as casks."
description: "Treat all named arguments as casks." conflicts "--formula", "--cask"
conflicts "--formula", "--cask" end
named_args [:tap] def run
end begin
end original_stderr = $stderr.clone
$stderr.reopen(File.new("/dev/null", "w"))
def brewer_tap_content_info
args = brewer_tap_content_info_args.parse formulae = []
casks = []
formulae = []
casks = [] Tap.each do |tap|
next if ["homebrew/core", "homebrew/cask"].include?(tap.name)
Tap.each do |tap| next unless valid_tap? tap
next if ["homebrew/core", "homebrew/cask"].include?(tap.name)
unless args.cask?
unless args.cask? tap.formula_files.each do |formula_file|
tap.formula_files.each do |formula_file| formulae << Formulary.factory(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
end end
unless args.formula? private
tap.cask_files.each do |cask_file|
casks << Cask::CaskLoader::FromPathLoader.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