mirror of
https://github.com/donl/homebrew-cask-versions.git
synced 2026-07-17 06:16:47 -06:00
Merge pull request #8189 from rolandwalker/port_homebrew_prettylisting
port PrettyListing class from Homebrew-fork
This commit is contained in:
commit
04dddb8e03
4 changed files with 7 additions and 153 deletions
|
|
@ -44,7 +44,7 @@ class Cask::CLI::List < Cask::CLI::Base
|
|||
end
|
||||
|
||||
def self.list_files(cask)
|
||||
ohai "Raw contents of Cask directory:"
|
||||
ohai "Staged content:"
|
||||
Cask::PrettyListing.new(cask).print
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
require 'cmd/list' # for homebrew's ::PrettyListing
|
||||
|
||||
class Cask::PrettyListing
|
||||
attr_reader :cask
|
||||
def initialize(cask)
|
||||
|
|
@ -7,6 +5,7 @@ class Cask::PrettyListing
|
|||
end
|
||||
|
||||
def print
|
||||
::PrettyListing.new(cask.staged_path)
|
||||
files = cask.staged_path.find.reject(&:directory?)
|
||||
puts "#{cask.staged_path} (#{files.length} files)"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,145 +0,0 @@
|
|||
require "metafiles"
|
||||
|
||||
module Homebrew
|
||||
def list
|
||||
|
||||
# Use of exec means we don't explicitly exit
|
||||
list_unbrewed if ARGV.flag? '--unbrewed'
|
||||
|
||||
# Unbrewed uses the PREFIX, which will exist
|
||||
# Things below use the CELLAR, which doesn't until the first formula is installed.
|
||||
return unless HOMEBREW_CELLAR.exist?
|
||||
|
||||
if ARGV.include? '--pinned' or ARGV.include? '--versions'
|
||||
filtered_list
|
||||
elsif ARGV.named.empty?
|
||||
ENV['CLICOLOR'] = nil
|
||||
exec 'ls', *ARGV.options_only << HOMEBREW_CELLAR
|
||||
elsif ARGV.verbose? or not $stdout.tty?
|
||||
exec "find", *ARGV.kegs.map(&:to_s) + %w[-not -type d -print]
|
||||
else
|
||||
ARGV.kegs.each{ |keg| PrettyListing.new keg }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
UNBREWED_EXCLUDE_FILES = %w[.DS_Store]
|
||||
UNBREWED_EXCLUDE_PATHS = %w[
|
||||
bin/brew
|
||||
lib/gdk-pixbuf-2.0/*
|
||||
lib/gio/*
|
||||
lib/node_modules/*
|
||||
lib/python[23].[0-9]/*
|
||||
share/info/dir
|
||||
share/man/man1/brew.1
|
||||
share/man/whatis
|
||||
]
|
||||
|
||||
def list_unbrewed
|
||||
dirs = HOMEBREW_PREFIX.subdirs.map { |dir| dir.basename.to_s }
|
||||
dirs -= %w[Library Cellar .git]
|
||||
|
||||
# Exclude the repository and cache, if they are located under the prefix
|
||||
dirs.delete HOMEBREW_CACHE.relative_path_from(HOMEBREW_PREFIX).to_s
|
||||
dirs.delete HOMEBREW_REPOSITORY.relative_path_from(HOMEBREW_PREFIX).to_s
|
||||
dirs.delete 'etc'
|
||||
dirs.delete 'var'
|
||||
|
||||
args = dirs + %w[-type f (]
|
||||
args.concat UNBREWED_EXCLUDE_FILES.map { |f| %W[! -name #{f}] }.flatten
|
||||
args.concat UNBREWED_EXCLUDE_PATHS.map { |d| %W[! -path #{d}] }.flatten
|
||||
args.concat %w[)]
|
||||
|
||||
cd HOMEBREW_PREFIX
|
||||
exec 'find', *args
|
||||
end
|
||||
|
||||
def filtered_list
|
||||
names = if ARGV.named.empty?
|
||||
HOMEBREW_CELLAR.subdirs
|
||||
else
|
||||
ARGV.named.map{ |n| HOMEBREW_CELLAR+n }.select{ |pn| pn.exist? }
|
||||
end
|
||||
if ARGV.include? '--pinned'
|
||||
pinned_versions = {}
|
||||
names.each do |d|
|
||||
keg_pin = (HOMEBREW_LIBRARY/"PinnedKegs"/d.basename.to_s)
|
||||
if keg_pin.exist? or keg_pin.symlink?
|
||||
pinned_versions[d] = keg_pin.readlink.basename.to_s
|
||||
end
|
||||
end
|
||||
pinned_versions.each do |d, version|
|
||||
puts "#{d.basename}".concat(ARGV.include?('--versions') ? " #{version}" : '')
|
||||
end
|
||||
else # --versions without --pinned
|
||||
names.each do |d|
|
||||
versions = d.subdirs.map { |pn| pn.basename.to_s }
|
||||
next if ARGV.include?('--multiple') && versions.count < 2
|
||||
puts "#{d.basename} #{versions*' '}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class PrettyListing
|
||||
def initialize path
|
||||
Pathname.new(path).children.sort_by { |p| p.to_s.downcase }.each do |pn|
|
||||
case pn.basename.to_s
|
||||
when 'bin', 'sbin'
|
||||
pn.find { |pnn| puts pnn unless pnn.directory? }
|
||||
when 'lib'
|
||||
print_dir pn do |pnn|
|
||||
# dylibs have multiple symlinks and we don't care about them
|
||||
(pnn.extname == '.dylib' or pnn.extname == '.pc') and not pnn.symlink?
|
||||
end
|
||||
else
|
||||
if pn.directory?
|
||||
if pn.symlink?
|
||||
puts "#{pn} -> #{pn.readlink}"
|
||||
else
|
||||
print_dir pn
|
||||
end
|
||||
elsif Metafiles.list?(pn.basename.to_s)
|
||||
puts pn
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def print_dir root
|
||||
dirs = []
|
||||
remaining_root_files = []
|
||||
other = ''
|
||||
|
||||
root.children.sort.each do |pn|
|
||||
if pn.directory?
|
||||
dirs << pn
|
||||
elsif block_given? and yield pn
|
||||
puts pn
|
||||
other = 'other '
|
||||
else
|
||||
remaining_root_files << pn unless pn.basename.to_s == '.DS_Store'
|
||||
end
|
||||
end
|
||||
|
||||
dirs.each do |d|
|
||||
files = []
|
||||
d.find { |pn| files << pn unless pn.directory? }
|
||||
print_remaining_files files, d
|
||||
end
|
||||
|
||||
print_remaining_files remaining_root_files, root, other
|
||||
end
|
||||
|
||||
def print_remaining_files files, root, other = ''
|
||||
case files.length
|
||||
when 0
|
||||
# noop
|
||||
when 1
|
||||
puts files
|
||||
else
|
||||
puts "#{root}/ (#{files.length} #{other}files)"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -48,11 +48,11 @@ describe Cask::CLI::List do
|
|||
Cask::CLI::List.run('local-transmission', 'local-caffeine')
|
||||
}.must_output <<-OUTPUT.gsub(/^ */, '')
|
||||
==> App Symlinks managed by brew-cask:
|
||||
==> Raw contents of Cask directory:
|
||||
#{transmission.staged_path}/Transmission.app/Contents/ (489 files)
|
||||
==> Staged content:
|
||||
#{transmission.staged_path} (489 files)
|
||||
==> App Symlinks managed by brew-cask:
|
||||
==> Raw contents of Cask directory:
|
||||
#{caffeine.staged_path}/Caffeine.app/Contents/ (13 files)
|
||||
==> Staged content:
|
||||
#{caffeine.staged_path} (13 files)
|
||||
OUTPUT
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue