Class: Hbc::CLI::Info

Inherits:
AbstractCommand show all
Defined in:
Library/Homebrew/cask/lib/hbc/cli/info.rb

Instance Attribute Summary

Attributes inherited from AbstractCommand

#args

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractCommand

abstract?, command_name, needs_init?, run, visible

Methods included from Options

included, #process_arguments

Constructor Details

#initializeInfo

Returns a new instance of Info



4
5
6
7
# File 'Library/Homebrew/cask/lib/hbc/cli/info.rb', line 4

def initialize(*)
  super
  raise CaskUnspecifiedError if args.empty?
end

Class Method Details

.artifact_info(cask) ⇒ Object



78
79
80
81
82
83
84
85
# File 'Library/Homebrew/cask/lib/hbc/cli/info.rb', line 78

def self.artifact_info(cask)
  ohai "Artifacts"
  cask.artifacts.each do |artifact|
    next unless artifact.respond_to?(:install_phase)
    next unless DSL::ORDINARY_ARTIFACT_CLASSES.include?(artifact.class)
    puts artifact.to_s
  end
end

.formatted_url(url) ⇒ Object



31
32
33
# File 'Library/Homebrew/cask/lib/hbc/cli/info.rb', line 31

def self.formatted_url(url)
  "#{Tty.underline}#{url}#{Tty.reset}"
end

.helpObject



16
17
18
# File 'Library/Homebrew/cask/lib/hbc/cli/info.rb', line 16

def self.help
  "displays information about the given Cask"
end

.info(cask) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'Library/Homebrew/cask/lib/hbc/cli/info.rb', line 20

def self.info(cask)
  puts "#{cask.token}: #{cask.version}"
  puts Formatter.url(cask.homepage) if cask.homepage
  installation_info(cask)
  repo_info(cask)
  name_info(cask)
  language_info(cask)
  artifact_info(cask)
  Installer.print_caveats(cask)
end

.installation_info(cask) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'Library/Homebrew/cask/lib/hbc/cli/info.rb', line 35

def self.installation_info(cask)
  if cask.installed?
    cask.versions.each do |version|
      versioned_staged_path = cask.caskroom_path.join(version)

      puts versioned_staged_path.to_s
        .concat(" (")
        .concat(versioned_staged_path.exist? ? versioned_staged_path.abv : Formatter.error("does not exist"))
                                .concat(")")
    end
  else
    puts "Not installed"
  end
end

.language_info(cask) ⇒ Object



55
56
57
58
59
60
# File 'Library/Homebrew/cask/lib/hbc/cli/info.rb', line 55

def self.language_info(cask)
  return if cask.languages.empty?

  ohai "Languages"
  puts cask.languages.join(", ")
end

.name_info(cask) ⇒ Object



50
51
52
53
# File 'Library/Homebrew/cask/lib/hbc/cli/info.rb', line 50

def self.name_info(cask)
  ohai((cask.name.size > 1) ? "Names" : "Name")
  puts cask.name.empty? ? Formatter.error("None") : cask.name
end

.repo_info(cask) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'Library/Homebrew/cask/lib/hbc/cli/info.rb', line 62

def self.repo_info(cask)
  user, repo, token = QualifiedToken.parse(Hbc.all_tokens.detect { |t| t.split("/").last == cask.token })

  return if user.nil? || repo.nil?

  remote_tap = Tap.fetch(user, repo)

  url = if remote_tap.custom_remote? && !remote_tap.remote.nil?
    remote_tap.remote
  else
    "#{remote_tap.default_remote}/blob/master/Casks/#{token}.rb"
  end

  puts "From: #{Formatter.url(url)}"
end

Instance Method Details

#runObject



9
10
11
12
13
14
# File 'Library/Homebrew/cask/lib/hbc/cli/info.rb', line 9

def run
  casks.each do |cask|
    odebug "Getting info for Cask #{cask}"
    self.class.info(cask)
  end
end