brew/Library/Homebrew/cmd/tap-info.rb

91 lines
2.6 KiB
Ruby
Raw Normal View History

2019-04-17 18:25:08 +09:00
require "cli/parser"
2015-06-08 19:13:05 +08:00
module Homebrew
2016-09-26 01:44:51 +02:00
module_function
def tap_info_args
Homebrew::CLI::Parser.new do
usage_banner <<~EOS
`tap-info` [<options>] [<tap>]
Display detailed information about one or more provided <tap>.
Display a brief summary of all installed taps if no <tap> are passed.
EOS
switch "--installed",
description: "Display information on all installed taps."
flag "--json",
description: "Print a JSON representation of <taps>. Currently the default and only accepted "\
"value for <version> is `v1`. See the docs for examples of using the JSON "\
"output: <https://docs.brew.sh/Querying-Brew>"
switch :debug
end
end
2015-06-08 19:13:05 +08:00
def tap_info
tap_info_args.parse
if args.installed?
2015-06-08 19:13:05 +08:00
taps = Tap
else
taps = ARGV.named.sort.map do |name|
Tap.fetch(name)
2015-06-08 19:13:05 +08:00
end
end
if args.json
raise UsageError, "invalid JSON version: #{args.json}" unless ["v1", true].include? args.json
2017-10-28 14:56:51 +05:30
print_tap_json(taps.sort_by(&:to_s))
2015-06-08 19:13:05 +08:00
else
2017-10-28 14:56:51 +05:30
print_tap_info(taps.sort_by(&:to_s))
2015-06-08 19:13:05 +08:00
end
end
def print_tap_info(taps)
if taps.none?
tap_count = 0
formula_count = 0
command_count = 0
2015-07-22 18:07:30 +08:00
pinned_count = 0
private_count = 0
2015-06-08 19:13:05 +08:00
Tap.each do |tap|
tap_count += 1
formula_count += tap.formula_files.size
command_count += tap.command_files.size
2015-07-22 18:07:30 +08:00
pinned_count += 1 if tap.pinned?
private_count += 1 if tap.private?
2015-06-08 19:13:05 +08:00
end
info = "#{tap_count} #{"tap".pluralize(tap_count)}"
2015-07-22 18:07:30 +08:00
info += ", #{pinned_count} pinned"
info += ", #{private_count} private"
info += ", #{formula_count} #{"formula".pluralize(formula_count)}"
info += ", #{command_count} #{"command".pluralize(command_count)}"
2015-06-08 19:13:05 +08:00
info += ", #{Tap::TAP_DIRECTORY.abv}" if Tap::TAP_DIRECTORY.directory?
puts info
else
taps.each_with_index do |tap, i|
2016-09-10 10:24:57 +01:00
puts unless i.zero?
2015-06-08 19:13:05 +08:00
info = "#{tap}: "
if tap.installed?
info += tap.pinned? ? "pinned" : "unpinned"
info += ", private" if tap.private?
2018-07-02 00:11:42 +02:00
info += if (contents = tap.contents).empty?
", no commands/casks/formulae"
2018-06-20 20:35:24 +02:00
else
2018-07-02 00:11:42 +02:00
", #{contents.join(", ")}"
end
2015-06-08 19:13:05 +08:00
info += "\n#{tap.path} (#{tap.path.abv})"
info += "\nFrom: #{tap.remote.nil? ? "N/A" : tap.remote}"
2015-06-08 19:13:05 +08:00
else
info += "Not installed"
end
puts info
end
end
end
def print_tap_json(taps)
puts JSON.generate(taps.map(&:to_hash))
2015-06-08 19:13:05 +08:00
end
end