Merge pull request #14839 from hyuraku/move-cask/cmd/info-to-cask/info
Move `cask/cmd/info` to `cask/info`
This commit is contained in:
commit
9296db0c41
@ -12,7 +12,6 @@ require "cask/config"
|
|||||||
require "cask/cmd/abstract_command"
|
require "cask/cmd/abstract_command"
|
||||||
require "cask/cmd/audit"
|
require "cask/cmd/audit"
|
||||||
require "cask/cmd/fetch"
|
require "cask/cmd/fetch"
|
||||||
require "cask/cmd/info"
|
|
||||||
require "cask/cmd/install"
|
require "cask/cmd/install"
|
||||||
require "cask/cmd/list"
|
require "cask/cmd/list"
|
||||||
require "cask/cmd/reinstall"
|
require "cask/cmd/reinstall"
|
||||||
|
|||||||
@ -1,154 +0,0 @@
|
|||||||
# typed: false
|
|
||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
require "json"
|
|
||||||
|
|
||||||
module Cask
|
|
||||||
class Cmd
|
|
||||||
# Cask implementation of the `brew info` command.
|
|
||||||
#
|
|
||||||
# @api private
|
|
||||||
class Info < AbstractCommand
|
|
||||||
extend T::Sig
|
|
||||||
|
|
||||||
def self.parser
|
|
||||||
super do
|
|
||||||
flag "--json=",
|
|
||||||
description: "Output information in JSON format."
|
|
||||||
switch "--github",
|
|
||||||
description: "Open the GitHub source page for <Cask> in a browser. "
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def github_info(cask)
|
|
||||||
sourcefile_path = cask.sourcefile_path
|
|
||||||
dir = cask.tap.path
|
|
||||||
path = sourcefile_path.relative_path_from(dir)
|
|
||||||
remote = cask.tap.remote
|
|
||||||
github_remote_path(remote, path)
|
|
||||||
end
|
|
||||||
|
|
||||||
def github_remote_path(remote, path)
|
|
||||||
if remote =~ %r{^(?:https?://|git(?:@|://))github\.com[:/](.+)/(.+?)(?:\.git)?$}
|
|
||||||
"https://github.com/#{Regexp.last_match(1)}/#{Regexp.last_match(2)}/blob/HEAD/#{path}"
|
|
||||||
else
|
|
||||||
"#{remote}/#{path}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
sig { void }
|
|
||||||
def run
|
|
||||||
if args.json == "v1"
|
|
||||||
puts JSON.pretty_generate(args.named.to_casks.map(&:to_h))
|
|
||||||
elsif args.github?
|
|
||||||
raise CaskUnspecifiedError if args.no_named?
|
|
||||||
|
|
||||||
args.named.to_casks.map do |cask|
|
|
||||||
exec_browser(github_info(cask))
|
|
||||||
end
|
|
||||||
else
|
|
||||||
args.named.to_casks.each_with_index do |cask, i|
|
|
||||||
puts unless i.zero?
|
|
||||||
odebug "Getting info for Cask #{cask}"
|
|
||||||
self.class.info(cask)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.get_info(cask)
|
|
||||||
require "cask/installer"
|
|
||||||
|
|
||||||
output = +"#{title_info(cask)}\n"
|
|
||||||
output << "#{Formatter.url(cask.homepage)}\n" if cask.homepage
|
|
||||||
output << installation_info(cask)
|
|
||||||
repo = repo_info(cask)
|
|
||||||
output << "#{repo}\n" if repo
|
|
||||||
output << name_info(cask)
|
|
||||||
output << desc_info(cask)
|
|
||||||
language = language_info(cask)
|
|
||||||
output << language if language
|
|
||||||
output << "#{artifact_info(cask)}\n"
|
|
||||||
caveats = Installer.caveats(cask)
|
|
||||||
output << caveats if caveats
|
|
||||||
output
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.info(cask)
|
|
||||||
puts get_info(cask)
|
|
||||||
::Utils::Analytics.cask_output(cask, args: Homebrew::CLI::Args.new)
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.title_info(cask)
|
|
||||||
title = "#{oh1_title(cask.token)}: #{cask.version}"
|
|
||||||
title += " (auto_updates)" if cask.auto_updates
|
|
||||||
title
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.formatted_url(url)
|
|
||||||
"#{Tty.underline}#{url}#{Tty.reset}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.installation_info(cask)
|
|
||||||
return "Not installed\n" unless cask.installed?
|
|
||||||
|
|
||||||
install_info = +""
|
|
||||||
cask.versions.each do |version|
|
|
||||||
versioned_staged_path = cask.caskroom_path.join(version)
|
|
||||||
path_details = if versioned_staged_path.exist?
|
|
||||||
versioned_staged_path.abv
|
|
||||||
else
|
|
||||||
Formatter.error("does not exist")
|
|
||||||
end
|
|
||||||
install_info << "#{versioned_staged_path} (#{path_details})\n"
|
|
||||||
end
|
|
||||||
install_info.freeze
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.name_info(cask)
|
|
||||||
<<~EOS
|
|
||||||
#{ohai_title((cask.name.size > 1) ? "Names" : "Name")}
|
|
||||||
#{cask.name.empty? ? Formatter.error("None") : cask.name.join("\n")}
|
|
||||||
EOS
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.desc_info(cask)
|
|
||||||
<<~EOS
|
|
||||||
#{ohai_title("Description")}
|
|
||||||
#{cask.desc.nil? ? Formatter.error("None") : cask.desc}
|
|
||||||
EOS
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.language_info(cask)
|
|
||||||
return if cask.languages.empty?
|
|
||||||
|
|
||||||
<<~EOS
|
|
||||||
#{ohai_title("Languages")}
|
|
||||||
#{cask.languages.join(", ")}
|
|
||||||
EOS
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.repo_info(cask)
|
|
||||||
return if cask.tap.nil?
|
|
||||||
|
|
||||||
url = if cask.tap.custom_remote? && !cask.tap.remote.nil?
|
|
||||||
cask.tap.remote
|
|
||||||
else
|
|
||||||
"#{cask.tap.default_remote}/blob/HEAD/Casks/#{cask.token}.rb"
|
|
||||||
end
|
|
||||||
|
|
||||||
"From: #{Formatter.url(url)}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.artifact_info(cask)
|
|
||||||
artifact_output = ohai_title("Artifacts").dup
|
|
||||||
cask.artifacts.each do |artifact|
|
|
||||||
next unless artifact.respond_to?(:install_phase)
|
|
||||||
next unless DSL::ORDINARY_ARTIFACT_CLASSES.include?(artifact.class)
|
|
||||||
|
|
||||||
artifact_output << "\n" << artifact.to_s
|
|
||||||
end
|
|
||||||
artifact_output.freeze
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
101
Library/Homebrew/cask/info.rb
Normal file
101
Library/Homebrew/cask/info.rb
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
# typed: false
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "json"
|
||||||
|
|
||||||
|
module Cask
|
||||||
|
#
|
||||||
|
# @api private
|
||||||
|
class Info
|
||||||
|
def self.get_info(cask)
|
||||||
|
require "cask/installer"
|
||||||
|
|
||||||
|
output = +"#{title_info(cask)}\n"
|
||||||
|
output << "#{Formatter.url(cask.homepage)}\n" if cask.homepage
|
||||||
|
output << installation_info(cask)
|
||||||
|
repo = repo_info(cask)
|
||||||
|
output << "#{repo}\n" if repo
|
||||||
|
output << name_info(cask)
|
||||||
|
output << desc_info(cask)
|
||||||
|
language = language_info(cask)
|
||||||
|
output << language if language
|
||||||
|
output << "#{artifact_info(cask)}\n"
|
||||||
|
caveats = Installer.caveats(cask)
|
||||||
|
output << caveats if caveats
|
||||||
|
output
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.info(cask)
|
||||||
|
puts get_info(cask)
|
||||||
|
::Utils::Analytics.cask_output(cask, args: Homebrew::CLI::Args.new)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.title_info(cask)
|
||||||
|
title = "#{oh1_title(cask.token)}: #{cask.version}"
|
||||||
|
title += " (auto_updates)" if cask.auto_updates
|
||||||
|
title
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.installation_info(cask)
|
||||||
|
return "Not installed\n" unless cask.installed?
|
||||||
|
|
||||||
|
install_info = +""
|
||||||
|
cask.versions.each do |version|
|
||||||
|
versioned_staged_path = cask.caskroom_path.join(version)
|
||||||
|
path_details = if versioned_staged_path.exist?
|
||||||
|
versioned_staged_path.abv
|
||||||
|
else
|
||||||
|
Formatter.error("does not exist")
|
||||||
|
end
|
||||||
|
install_info << "#{versioned_staged_path} (#{path_details})\n"
|
||||||
|
end
|
||||||
|
install_info.freeze
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.name_info(cask)
|
||||||
|
<<~EOS
|
||||||
|
#{ohai_title((cask.name.size > 1) ? "Names" : "Name")}
|
||||||
|
#{cask.name.empty? ? Formatter.error("None") : cask.name.join("\n")}
|
||||||
|
EOS
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.desc_info(cask)
|
||||||
|
<<~EOS
|
||||||
|
#{ohai_title("Description")}
|
||||||
|
#{cask.desc.nil? ? Formatter.error("None") : cask.desc}
|
||||||
|
EOS
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.language_info(cask)
|
||||||
|
return if cask.languages.empty?
|
||||||
|
|
||||||
|
<<~EOS
|
||||||
|
#{ohai_title("Languages")}
|
||||||
|
#{cask.languages.join(", ")}
|
||||||
|
EOS
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.repo_info(cask)
|
||||||
|
return if cask.tap.nil?
|
||||||
|
|
||||||
|
url = if cask.tap.custom_remote? && !cask.tap.remote.nil?
|
||||||
|
cask.tap.remote
|
||||||
|
else
|
||||||
|
"#{cask.tap.default_remote}/blob/HEAD/Casks/#{cask.token}.rb"
|
||||||
|
end
|
||||||
|
|
||||||
|
"From: #{Formatter.url(url)}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.artifact_info(cask)
|
||||||
|
artifact_output = ohai_title("Artifacts").dup
|
||||||
|
cask.artifacts.each do |artifact|
|
||||||
|
next unless artifact.respond_to?(:install_phase)
|
||||||
|
next unless DSL::ORDINARY_ARTIFACT_CLASSES.include?(artifact.class)
|
||||||
|
|
||||||
|
artifact_output << "\n" << artifact.to_s
|
||||||
|
end
|
||||||
|
artifact_output.freeze
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -375,9 +375,8 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
def info_cask(cask, args:)
|
def info_cask(cask, args:)
|
||||||
require "cask/cmd"
|
require "cask/info"
|
||||||
require "cask/cmd/info"
|
|
||||||
|
|
||||||
Cask::Cmd::Info.info(cask)
|
Cask::Info.info(cask)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "cask/cmd/abstract_command"
|
require "cask/cmd/abstract_command"
|
||||||
require "cask/cmd/info"
|
require "cask/info"
|
||||||
require "cask/cask_loader"
|
require "cask/cask_loader"
|
||||||
require "cask/caskroom"
|
require "cask/caskroom"
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ module Homebrew
|
|||||||
suggestion = <<~EOS
|
suggestion = <<~EOS
|
||||||
Found a cask named "#{name}" instead.
|
Found a cask named "#{name}" instead.
|
||||||
|
|
||||||
#{Cask::Cmd::Info.get_info(cask)}
|
#{Cask::Info.get_info(cask)}
|
||||||
EOS
|
EOS
|
||||||
else
|
else
|
||||||
return
|
return
|
||||||
|
|||||||
@ -3,10 +3,10 @@
|
|||||||
|
|
||||||
require "utils"
|
require "utils"
|
||||||
|
|
||||||
describe Cask::Cmd::Info, :cask do
|
describe Cask::Info, :cask do
|
||||||
it "displays some nice info about the specified Cask" do
|
it "displays some nice info about the specified Cask" do
|
||||||
expect {
|
expect {
|
||||||
described_class.run("local-transmission")
|
described_class.info(Cask::CaskLoader.load("local-transmission"))
|
||||||
}.to output(<<~EOS).to_stdout
|
}.to output(<<~EOS).to_stdout
|
||||||
==> local-transmission: 2.61
|
==> local-transmission: 2.61
|
||||||
https://transmissionbt.com/
|
https://transmissionbt.com/
|
||||||
@ -23,7 +23,7 @@ describe Cask::Cmd::Info, :cask do
|
|||||||
|
|
||||||
it "prints auto_updates if the Cask has `auto_updates true`" do
|
it "prints auto_updates if the Cask has `auto_updates true`" do
|
||||||
expect {
|
expect {
|
||||||
described_class.run("with-auto-updates")
|
described_class.info(Cask::CaskLoader.load("with-auto-updates"))
|
||||||
}.to output(<<~EOS).to_stdout
|
}.to output(<<~EOS).to_stdout
|
||||||
==> with-auto-updates: 1.0 (auto_updates)
|
==> with-auto-updates: 1.0 (auto_updates)
|
||||||
https://brew.sh/autoupdates
|
https://brew.sh/autoupdates
|
||||||
@ -38,43 +38,9 @@ describe Cask::Cmd::Info, :cask do
|
|||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "given multiple Casks" do
|
|
||||||
let(:expected_output) {
|
|
||||||
<<~EOS
|
|
||||||
==> local-caffeine: 1.2.3
|
|
||||||
https://brew.sh/
|
|
||||||
Not installed
|
|
||||||
From: https://github.com/Homebrew/homebrew-cask/blob/HEAD/Casks/local-caffeine.rb
|
|
||||||
==> Name
|
|
||||||
None
|
|
||||||
==> Description
|
|
||||||
None
|
|
||||||
==> Artifacts
|
|
||||||
Caffeine.app (App)
|
|
||||||
|
|
||||||
==> local-transmission: 2.61
|
|
||||||
https://transmissionbt.com/
|
|
||||||
Not installed
|
|
||||||
From: https://github.com/Homebrew/homebrew-cask/blob/HEAD/Casks/local-transmission.rb
|
|
||||||
==> Name
|
|
||||||
Transmission
|
|
||||||
==> Description
|
|
||||||
BitTorrent client
|
|
||||||
==> Artifacts
|
|
||||||
Transmission.app (App)
|
|
||||||
EOS
|
|
||||||
}
|
|
||||||
|
|
||||||
it "displays the info" do
|
|
||||||
expect {
|
|
||||||
described_class.run("local-caffeine", "local-transmission")
|
|
||||||
}.to output(expected_output).to_stdout
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
it "prints caveats if the Cask provided one" do
|
it "prints caveats if the Cask provided one" do
|
||||||
expect {
|
expect {
|
||||||
described_class.run("with-caveats")
|
described_class.info(Cask::CaskLoader.load("with-caveats"))
|
||||||
}.to output(<<~EOS).to_stdout
|
}.to output(<<~EOS).to_stdout
|
||||||
==> with-caveats: 1.2.3
|
==> with-caveats: 1.2.3
|
||||||
https://brew.sh/
|
https://brew.sh/
|
||||||
@ -101,7 +67,7 @@ describe Cask::Cmd::Info, :cask do
|
|||||||
|
|
||||||
it 'does not print "Caveats" section divider if the caveats block has no output' do
|
it 'does not print "Caveats" section divider if the caveats block has no output' do
|
||||||
expect {
|
expect {
|
||||||
described_class.run("with-conditional-caveats")
|
described_class.info(Cask::CaskLoader.load("with-conditional-caveats"))
|
||||||
}.to output(<<~EOS).to_stdout
|
}.to output(<<~EOS).to_stdout
|
||||||
==> with-conditional-caveats: 1.2.3
|
==> with-conditional-caveats: 1.2.3
|
||||||
https://brew.sh/
|
https://brew.sh/
|
||||||
@ -118,7 +84,7 @@ describe Cask::Cmd::Info, :cask do
|
|||||||
|
|
||||||
it "prints languages specified in the Cask" do
|
it "prints languages specified in the Cask" do
|
||||||
expect {
|
expect {
|
||||||
described_class.run("with-languages")
|
described_class.info(Cask::CaskLoader.load("with-languages"))
|
||||||
}.to output(<<~EOS).to_stdout
|
}.to output(<<~EOS).to_stdout
|
||||||
==> with-languages: 1.2.3
|
==> with-languages: 1.2.3
|
||||||
https://brew.sh/
|
https://brew.sh/
|
||||||
@ -137,7 +103,7 @@ describe Cask::Cmd::Info, :cask do
|
|||||||
|
|
||||||
it 'does not print "Languages" section divider if the languages block has no output' do
|
it 'does not print "Languages" section divider if the languages block has no output' do
|
||||||
expect {
|
expect {
|
||||||
described_class.run("without-languages")
|
described_class.info(Cask::CaskLoader.load("without-languages"))
|
||||||
}.to output(<<~EOS).to_stdout
|
}.to output(<<~EOS).to_stdout
|
||||||
==> without-languages: 1.2.3
|
==> without-languages: 1.2.3
|
||||||
https://brew.sh/
|
https://brew.sh/
|
||||||
Loading…
x
Reference in New Issue
Block a user