diff options
| author | Mike McQuaid | 2017-02-26 20:48:36 +0000 |
|---|---|---|
| committer | Mike McQuaid | 2017-02-26 20:48:36 +0000 |
| commit | c2a460ec6d857ba33c89174d8d93fcaa403c3717 (patch) | |
| tree | 089045fec4c46fb74e3b48868e2b335497df7b84 /Library/Homebrew/cask/lib/hbc/cli | |
| parent | d3ae1cc264dc9eb9b602dd6aa21c4282dc049c79 (diff) | |
| parent | ff93e1624b214c9b48731174a9135789fc3695a8 (diff) | |
| download | brew-c2a460ec6d857ba33c89174d8d93fcaa403c3717.tar.bz2 | |
Merge branch 'master' into filter_all_env_vars_932
Diffstat (limited to 'Library/Homebrew/cask/lib/hbc/cli')
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cli/doctor.rb | 175 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cli/fetch.rb | 4 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb | 61 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cli/internal_help.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb | 20 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cli/list.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cli/style.rb | 4 |
8 files changed, 131 insertions, 139 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/cli/doctor.rb b/Library/Homebrew/cask/lib/hbc/cli/doctor.rb index 84d8e1ebc..6b2f4caab 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/doctor.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/doctor.rb @@ -2,116 +2,39 @@ module Hbc class CLI class Doctor < Base def self.run - ohai "macOS Release:", render_with_none_as_error(MacOS.full_version) - ohai "Hardware Architecture:", render_with_none_as_error("#{Hardware::CPU.type}-#{Hardware::CPU.bits}") - ohai "Ruby Version:", render_with_none_as_error("#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}") - ohai "Ruby Path:", render_with_none_as_error(RbConfig.ruby) - # TODO: consider removing most Homebrew constants from doctor output - ohai "Homebrew Version:", render_with_none_as_error(homebrew_version) - ohai "Homebrew Executable Path:", render_with_none_as_error(HOMEBREW_BREW_FILE) - ohai "Homebrew Cellar Path:", render_with_none_as_error(homebrew_cellar) - ohai "Homebrew Repository Path:", render_with_none_as_error(HOMEBREW_REPOSITORY) - ohai "Homebrew Origin:", render_with_none_as_error(homebrew_origin) - ohai "Homebrew-Cask Version:", render_with_none_as_error(Hbc.full_version) - ohai "Homebrew-Cask Install Location:", render_install_location - ohai "Homebrew-Cask Staging Location:", render_staging_location(Hbc.caskroom) - ohai "Homebrew-Cask Cached Downloads:", render_cached_downloads - ohai "Homebrew-Cask Default Tap Path:", render_tap_paths(Hbc.default_tap.path) - ohai "Homebrew-Cask Alternate Cask Taps:", render_tap_paths(alt_taps) - ohai "Homebrew-Cask Default Tap Cask Count:", render_with_none_as_error(default_cask_count) - ohai "Contents of $LOAD_PATH:", render_load_path($LOAD_PATH) - ohai "Contents of $RUBYLIB Environment Variable:", render_env_var("RUBYLIB") - ohai "Contents of $RUBYOPT Environment Variable:", render_env_var("RUBYOPT") - ohai "Contents of $RUBYPATH Environment Variable:", render_env_var("RUBYPATH") - ohai "Contents of $RBENV_VERSION Environment Variable:", render_env_var("RBENV_VERSION") - ohai "Contents of $CHRUBY_VERSION Environment Variable:", render_env_var("CHRUBY_VERSION") - ohai "Contents of $GEM_HOME Environment Variable:", render_env_var("GEM_HOME") - ohai "Contents of $GEM_PATH Environment Variable:", render_env_var("GEM_PATH") - ohai "Contents of $BUNDLE_PATH Environment Variable:", render_env_var("BUNDLE_PATH") - ohai "Contents of $PATH Environment Variable:", render_env_var("PATH") - ohai "Contents of $SHELL Environment Variable:", render_env_var("SHELL") - ohai "Contents of Locale Environment Variables:", render_with_none(locale_variables) - end - - def self.alt_taps - Tap.select { |t| t.cask_dir && t != Hbc.default_tap } - .map(&:path) - end - - def self.default_cask_count - Hbc.default_tap.cask_files.count - rescue StandardError - "0 #{error_string "Error reading #{Hbc.default_tap.path}"}" - end - - def self.homebrew_origin - homebrew_origin = notfound_string - begin - Dir.chdir(HOMEBREW_REPOSITORY) do - homebrew_origin = SystemCommand.run("/usr/bin/git", - args: %w[config --get remote.origin.url], - print_stderr: false).stdout.strip - end - if homebrew_origin !~ /\S/ - homebrew_origin = "#{none_string} #{error_string}" - elsif homebrew_origin !~ %r{(mxcl|Homebrew)/(home)?brew(\.git)?\Z} - homebrew_origin.concat " #{error_string "warning: nonstandard origin"}" - end - rescue StandardError - homebrew_origin = error_string "Not Found - Error running git" - end - homebrew_origin - end - - def self.homebrew_cellar - homebrew_constants("cellar") - end - - def self.homebrew_version - homebrew_constants("version") - end - - def self.homebrew_taps - Tap::TAP_DIRECTORY - end - - def self.homebrew_constants(name) - @homebrew_constants ||= {} - return @homebrew_constants[name] if @homebrew_constants.key?(name) - @homebrew_constants[name] = notfound_string - begin - @homebrew_constants[name] = SystemCommand.run!(HOMEBREW_BREW_FILE, - args: ["--#{name}"], - print_stderr: false) - .stdout - .strip - if @homebrew_constants[name] !~ /\S/ - @homebrew_constants[name] = "#{none_string} #{error_string}" - end - path = Pathname.new(@homebrew_constants[name]) - @homebrew_constants[name] = path if path.exist? - rescue StandardError - @homebrew_constants[name] = error_string "Not Found - Error running brew" - end - @homebrew_constants[name] + ohai "Homebrew-Cask Version", Hbc.full_version + ohai "Homebrew-Cask Install Location", render_install_location + ohai "Homebrew-Cask Staging Location", render_staging_location(Hbc.caskroom) + ohai "Homebrew-Cask Cached Downloads", render_cached_downloads + ohai "Homebrew-Cask Taps:" + puts render_taps(Hbc.default_tap, *alt_taps) + ohai "Contents of $LOAD_PATH", render_load_path($LOAD_PATH) + ohai "Environment Variables" + + environment_variables = [ + "RUBYLIB", + "RUBYOPT", + "RUBYPATH", + "RBENV_VERSION", + "CHRUBY_VERSION", + "GEM_HOME", + "GEM_PATH", + "BUNDLE_PATH", + "PATH", + "SHELL", + ] + + (locale_variables + environment_variables).sort.each(&method(:render_env_var)) end def self.locale_variables - ENV.keys.grep(/^(?:LC_\S+|LANG|LANGUAGE)\Z/).collect { |v| %Q(#{v}="#{ENV[v]}") }.sort.join("\n") + ENV.keys.grep(/^(?:LC_\S+|LANG|LANGUAGE)\Z/).sort end def self.none_string "<NONE>" end - def self.legacy_tap_pattern - /phinze/ - end - - def self.notfound_string - Formatter.error("Not Found - Unknown Error") - end - def self.error_string(string = "Error") Formatter.error("(#{string})") end @@ -121,37 +44,42 @@ module Hbc none_string end - def self.render_with_none_as_error(string) - return string if !string.nil? && string.respond_to?(:to_s) && !string.to_s.empty? - "#{none_string} #{error_string}" + def self.alt_taps + Tap.select { |t| t.cask_dir && t != Hbc.default_tap } end - def self.render_tap_paths(paths) - paths = [paths] unless paths.respond_to?(:each) - paths.collect do |dir| - if dir.nil? || dir.to_s.empty? + def self.cask_count_for_tap(tap) + count = tap.cask_files.count + "#{count} #{count == 1 ? "cask" : "casks"}" + rescue StandardError + "0 #{error_string "error reading #{tap.path}"}" + end + + def self.render_taps(*taps) + taps.collect do |tap| + if tap.path.nil? || tap.path.to_s.empty? none_string - elsif dir.to_s.match(legacy_tap_pattern) - dir.to_s.concat(" #{error_string "Warning: legacy tap path"}") else - dir.to_s + "#{tap.path} (#{cask_count_for_tap(tap)})" end end end def self.render_env_var(var) - if ENV.key?(var) - %Q(#{var}="#{ENV[var]}") - else - none_string - end + return unless ENV.key?(var) + var = %Q(#{var}="#{ENV[var]}") + puts user_tilde(var) + end + + def self.user_tilde(path) + path.gsub(ENV["HOME"], "~") end # This could be done by calling into Homebrew, but the situation # where "doctor" is needed is precisely the situation where such # things are less dependable. def self.render_install_location - locations = Dir.glob(Pathname.new(homebrew_cellar).join("brew-cask", "*")).reverse + locations = Dir.glob(HOMEBREW_CELLAR.join("brew-cask", "*")).reverse if locations.empty? none_string else @@ -162,7 +90,7 @@ module Hbc end def self.render_staging_location(path) - path = Pathname.new(path) + path = Pathname.new(user_tilde(path.to_s)) if !path.exist? "#{path} #{error_string "error: path does not exist"}}" elsif !path.writable? @@ -173,19 +101,18 @@ module Hbc end def self.render_load_path(paths) + paths.map(&method(:user_tilde)) return "#{none_string} #{error_string}" if [*paths].empty? paths end def self.render_cached_downloads cleanup = CLI::Cleanup.default - files = cleanup.cache_files - count = files.count + count = cleanup.cache_files.count size = cleanup.disk_cleanup_size - size_msg = "#{number_readable(count)} files, #{disk_usage_readable(size)}" - warn_msg = error_string('warning: run "brew cask cleanup"') - size_msg << " #{warn_msg}" if count > 0 - [Hbc.cache, size_msg] + msg = user_tilde(Hbc.cache.to_s) + msg << " (#{number_readable(count)} files, #{disk_usage_readable(size)})" unless count.zero? + msg end def self.help diff --git a/Library/Homebrew/cask/lib/hbc/cli/fetch.rb b/Library/Homebrew/cask/lib/hbc/cli/fetch.rb index 9b3d5099c..fc928586f 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/fetch.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/fetch.rb @@ -15,6 +15,10 @@ module Hbc end end + def self.needs_init? + true + end + def self.help "downloads remote application files to local cache" end diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb new file mode 100644 index 000000000..790e917b2 --- /dev/null +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb @@ -0,0 +1,61 @@ +module Hbc + class CLI + class InternalAppcastCheckpoint < InternalUseBase + def self.run(*args) + calculate = args.include? "--calculate" + cask_tokens = cask_tokens_from(args) + raise CaskUnspecifiedError if cask_tokens.empty? + + if cask_tokens.all? { |t| t =~ %r{^https?://} && t !~ /\.rb$/ } + appcask_checkpoint_for_url(cask_tokens) + else + appcask_checkpoint(cask_tokens, calculate) + end + end + + def self.appcask_checkpoint_for_url(urls) + urls.each do |url| + appcast = DSL::Appcast.new(url) + puts appcast.calculate_checkpoint[:checkpoint] + end + end + + def self.appcask_checkpoint(cask_tokens, calculate) + count = 0 + + cask_tokens.each do |cask_token| + cask = Hbc.load(cask_token) + + if cask.appcast.nil? + opoo "Cask '#{cask}' is missing an `appcast` stanza." + else + if calculate + result = cask.appcast.calculate_checkpoint + + checkpoint = result[:checkpoint] + else + checkpoint = cask.appcast.checkpoint + end + + if checkpoint.nil? + onoe "Could not retrieve `appcast` checkpoint for cask '#{cask}': #{result[:command_result].stderr}" + else + puts cask_tokens.count > 1 ? "#{checkpoint} #{cask}": checkpoint + count += 1 + end + end + end + + count == cask_tokens.count + end + + def self.help + "prints or calculates a given Cask's or URL's appcast checkpoint" + end + + def self.needs_init? + true + end + end + end +end diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb index af1494e5f..ac1b20493 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb @@ -27,7 +27,7 @@ module Hbc end def self.help - "Dump the given Cask in YAML format" + "dump the given Cask in YAML format" end end end diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_help.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_help.rb index 6c646cfd7..0908ee05e 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_help.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_help.rb @@ -16,7 +16,7 @@ module Hbc end def self.help - "Print help strings for unstable internal-use commands" + "print help strings for unstable internal-use commands" end end end diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb index e5c04ee51..c54db8795 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb @@ -44,18 +44,20 @@ module Hbc :stage_only, :nested_container, :uninstall, - :postflight, - :uninstall_postflight, :preflight, + :postflight, + :uninstall_preflight, :uninstall_postflight, ] - def self.run(*arguments) - table = arguments.include? "--table" - quiet = arguments.include? "--quiet" - format = :to_yaml if arguments.include? "--yaml" - format = :inspect if arguments.include? "--inspect" - cask_tokens = arguments.reject { |arg| arg.chars.first == "-" } + def self.run(*args) + raise ArgumentError, "No stanza given." if args.empty? + + table = args.include? "--table" + quiet = args.include? "--quiet" + format = :to_yaml if args.include? "--yaml" + format = :inspect if args.include? "--inspect" + cask_tokens = cask_tokens_from(args) stanza = cask_tokens.shift.to_sym cask_tokens = Hbc.all_tokens if cask_tokens.empty? @@ -125,7 +127,7 @@ module Hbc end def self.help - "Extract and render a specific stanza for the given Casks" + "extract and render a specific stanza for the given Casks" end end end diff --git a/Library/Homebrew/cask/lib/hbc/cli/list.rb b/Library/Homebrew/cask/lib/hbc/cli/list.rb index 4094b3d38..e100fbd83 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/list.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/list.rb @@ -55,7 +55,7 @@ module Hbc def self.list_artifacts(cask) Artifact.for_cask(cask).each do |artifact| - summary = artifact.new(cask).summary + summary = artifact.summary ohai summary[:english_description], summary[:contents] unless summary.empty? end end diff --git a/Library/Homebrew/cask/lib/hbc/cli/style.rb b/Library/Homebrew/cask/lib/hbc/cli/style.rb index cdcc135b8..d3e44382d 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/style.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/style.rb @@ -23,12 +23,10 @@ module Hbc $CHILD_STATUS.success? end - RUBOCOP_CASK_VERSION = "~> 0.10.6".freeze - def install_rubocop Utils.capture_stderr do begin - Homebrew.install_gem_setup_path! "rubocop-cask", RUBOCOP_CASK_VERSION, "rubocop" + Homebrew.install_gem_setup_path! "rubocop-cask", HOMEBREW_RUBOCOP_CASK_VERSION, "rubocop" rescue SystemExit raise CaskError, Tty.strip_ansi($stderr.string).chomp.sub(/\AError: /, "") end |
