homebrew-cask-versions/lib/cask/cli/info.rb
Roland Walker 88b2e92015 DSL: add stanza stage_only (new caskroom_only)
`caskroom_only` was never documented.  Its original purpose was
obsoleted in #4865, and its use has been recently been reduced to
two Casks.

This PR
* continues the rationalization of naming by changing `caskroom_only`
  to `stage_only`. "stage" is the verb for "make a copy under the
  caskroom directory"
* documents `stage_only`
* adds tests for `stage_only`
* validates the argument to `stage_only`
* gives sensible output in `brew cask info` for `stage_only` Casks
* enforces that `stage_only` cannot coexist with any activatable
  artifacts

`caskroom_only` is still supported for backward compatibility,
but should be removed before 0.50.0.
2014-11-18 07:13:15 -05:00

66 lines
2.1 KiB
Ruby

class Cask::CLI::Info < Cask::CLI::Base
def self.run(*args)
cask_names = cask_names_from(args)
raise CaskUnspecifiedError if cask_names.empty?
cask_names.each do |cask_name|
odebug "Getting info for Cask #{cask_name}"
cask = Cask.load(cask_name)
puts info(cask)
Cask::Installer.print_caveats(cask)
end
end
def self.help
"displays information about the Cask of the given name"
end
def self.info(cask)
installation = if cask.installed?
"#{cask.staged_path} (#{cask.staged_path.cabv})"
else
"Not installed"
end
<<-PURPOSE
#{cask}: #{cask.version}
#{cask.homepage or 'No Homepage'}
#{installation}
#{github_info(cask) or 'No GitHub URL'}
#{artifact_info(cask) or 'No Artifact Info'}
PURPOSE
end
def self.github_info(cask)
title = cask.title
title = cask.class.all_titles.detect { |t| t.split("/").last == title } unless title =~ /\//
return nil unless title.respond_to?(:length) and title.length > 0
path_elements = title.split '/'
if path_elements.count == 2
# eg caskroom-cask/google-chrome.
# Not certain this form is needed, but it was supported in the past.
name = path_elements[1]
dash_elements = path_elements[0].split('-')
repo = dash_elements.pop
dash_elements.pop if dash_elements.count > 1 and dash_elements[-1] + '-' == repo_prefix
user = dash_elements.join('-')
else
user, repo, name = path_elements
end
repo.sub!(/^homebrew-/i, '')
"https://github.com/#{user}/homebrew-#{repo}/blob/master/Casks/#{name}.rb"
end
def self.artifact_info(cask)
retval = ''
Cask::DSL::ClassMethods.ordinary_artifact_types.each do |type|
if cask.artifacts[type].length > 0
retval = "#{Tty.blue}==>#{Tty.white} Contents#{Tty.reset}\n" unless retval.length > 0
cask.artifacts[type].each do |artifact|
activatable_item = type == :stage_only ? '<none>' : artifact.first
retval.concat " #{activatable_item} (#{type.to_s})\n"
end
end
end
retval.sub!(/\n\Z/, '')
end
end