From acc7309ca34a28d340583bad619e236b6bc78e52 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 20 May 2017 19:08:03 +0200 Subject: [PATCH] Rename `Base` and `InternalUseBase`. --- Library/Homebrew/cask/lib/hbc/cli.rb | 9 +++++---- Library/Homebrew/cask/lib/hbc/cli/--version.rb | 2 +- .../cask/lib/hbc/cli/{base.rb => abstract_command.rb} | 10 +++++++++- ...ternal_use_base.rb => abstract_internal_command.rb} | 2 +- Library/Homebrew/cask/lib/hbc/cli/audit.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/cat.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/cleanup.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/create.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/doctor.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/edit.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/fetch.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/home.rb | 6 +----- Library/Homebrew/cask/lib/hbc/cli/info.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/install.rb | 2 +- .../cask/lib/hbc/cli/internal_appcast_checkpoint.rb | 2 +- .../cask/lib/hbc/cli/internal_audit_modified_casks.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/internal_checkurl.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/internal_help.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/list.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/outdated.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/search.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/style.rb | 6 +----- Library/Homebrew/cask/lib/hbc/cli/uninstall.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/zap.rb | 2 +- Library/Homebrew/compat/hbc/cli/update.rb | 4 ++-- 27 files changed, 40 insertions(+), 39 deletions(-) rename Library/Homebrew/cask/lib/hbc/cli/{base.rb => abstract_command.rb} (72%) rename Library/Homebrew/cask/lib/hbc/cli/{internal_use_base.rb => abstract_internal_command.rb} (76%) diff --git a/Library/Homebrew/cask/lib/hbc/cli.rb b/Library/Homebrew/cask/lib/hbc/cli.rb index d0c4f30df8..3f6af2c340 100644 --- a/Library/Homebrew/cask/lib/hbc/cli.rb +++ b/Library/Homebrew/cask/lib/hbc/cli.rb @@ -3,7 +3,7 @@ require "shellwords" require "extend/optparse" -require "hbc/cli/base" +require "hbc/cli/abstract_command" require "hbc/cli/audit" require "hbc/cli/cat" require "hbc/cli/cleanup" @@ -23,7 +23,7 @@ require "hbc/cli/uninstall" require "hbc/cli/--version" require "hbc/cli/zap" -require "hbc/cli/internal_use_base" +require "hbc/cli/abstract_internal_command" require "hbc/cli/internal_audit_modified_casks" require "hbc/cli/internal_appcast_checkpoint" require "hbc/cli/internal_checkurl" @@ -90,7 +90,8 @@ module Hbc def self.command_classes @command_classes ||= constants.map(&method(:const_get)) - .select { |sym| sym.respond_to?(:run) } + .select { |klass| klass.respond_to?(:run) } + .reject(&:abstract?) .sort_by(&:command_name) end @@ -105,7 +106,7 @@ module Hbc end def self.should_init?(command) - (command.is_a? Class) && (command < CLI::Base) && command.needs_init? + command.is_a?(Class) && !command.abstract? && command.needs_init? end def self.run_command(command, *rest) diff --git a/Library/Homebrew/cask/lib/hbc/cli/--version.rb b/Library/Homebrew/cask/lib/hbc/cli/--version.rb index 253772ebe9..23ecde0cc0 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/--version.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/--version.rb @@ -1,6 +1,6 @@ module Hbc class CLI - class Version < Base + class Version < AbstractCommand def self.command_name "--#{super}" end diff --git a/Library/Homebrew/cask/lib/hbc/cli/base.rb b/Library/Homebrew/cask/lib/hbc/cli/abstract_command.rb similarity index 72% rename from Library/Homebrew/cask/lib/hbc/cli/base.rb rename to Library/Homebrew/cask/lib/hbc/cli/abstract_command.rb index 1ad347de3f..0f9f05f94b 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/base.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/abstract_command.rb @@ -1,10 +1,14 @@ module Hbc class CLI - class Base + class AbstractCommand def self.command_name @command_name ||= name.sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1_\2').downcase end + def self.abstract? + !(name.split("::").last !~ /^Abstract[^a-z]/) + end + def self.visible true end @@ -21,6 +25,10 @@ module Hbc false end + def self.run(*args) + new(*args).run + end + def initialize(*args) @args = args end diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_use_base.rb b/Library/Homebrew/cask/lib/hbc/cli/abstract_internal_command.rb similarity index 76% rename from Library/Homebrew/cask/lib/hbc/cli/internal_use_base.rb rename to Library/Homebrew/cask/lib/hbc/cli/abstract_internal_command.rb index b1f9c5631f..8af71e5895 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_use_base.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/abstract_internal_command.rb @@ -1,6 +1,6 @@ module Hbc class CLI - class InternalUseBase < Base + class AbstractInternalCommand < AbstractCommand def self.command_name super.sub(/^internal_/i, "_") end diff --git a/Library/Homebrew/cask/lib/hbc/cli/audit.rb b/Library/Homebrew/cask/lib/hbc/cli/audit.rb index 5da2be4cfb..06cccb6acf 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/audit.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/audit.rb @@ -1,6 +1,6 @@ module Hbc class CLI - class Audit < Base + class Audit < AbstractCommand def self.help "verifies installability of Casks" end diff --git a/Library/Homebrew/cask/lib/hbc/cli/cat.rb b/Library/Homebrew/cask/lib/hbc/cli/cat.rb index 774b96e89c..ca72259262 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/cat.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/cat.rb @@ -1,6 +1,6 @@ module Hbc class CLI - class Cat < Base + class Cat < AbstractCommand def self.run(*args) new(*args).run end diff --git a/Library/Homebrew/cask/lib/hbc/cli/cleanup.rb b/Library/Homebrew/cask/lib/hbc/cli/cleanup.rb index a62b8d069a..c605fea7ce 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/cleanup.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/cleanup.rb @@ -1,6 +1,6 @@ module Hbc class CLI - class Cleanup < Base + class Cleanup < AbstractCommand OUTDATED_DAYS = 10 OUTDATED_TIMESTAMP = Time.now - (60 * 60 * 24 * OUTDATED_DAYS) diff --git a/Library/Homebrew/cask/lib/hbc/cli/create.rb b/Library/Homebrew/cask/lib/hbc/cli/create.rb index 39b9bcda78..09de666493 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/create.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/create.rb @@ -1,6 +1,6 @@ module Hbc class CLI - class Create < Base + class Create < AbstractCommand def self.run(*args) new(*args).run end diff --git a/Library/Homebrew/cask/lib/hbc/cli/doctor.rb b/Library/Homebrew/cask/lib/hbc/cli/doctor.rb index 11917ae6b7..9a3dfcad4a 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/doctor.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/doctor.rb @@ -1,6 +1,6 @@ module Hbc class CLI - class Doctor < Base + class Doctor < AbstractCommand def self.run ohai "Homebrew-Cask Version", Hbc.full_version ohai "Homebrew-Cask Install Location", render_install_location diff --git a/Library/Homebrew/cask/lib/hbc/cli/edit.rb b/Library/Homebrew/cask/lib/hbc/cli/edit.rb index 52b089a8bc..f1797de1c8 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/edit.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/edit.rb @@ -1,6 +1,6 @@ module Hbc class CLI - class Edit < Base + class Edit < AbstractCommand def self.run(*args) new(*args).run end diff --git a/Library/Homebrew/cask/lib/hbc/cli/fetch.rb b/Library/Homebrew/cask/lib/hbc/cli/fetch.rb index f7139ff639..0d1a91e85c 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/fetch.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/fetch.rb @@ -1,6 +1,6 @@ module Hbc class CLI - class Fetch < Base + class Fetch < AbstractCommand def self.run(*args) new(*args).run end diff --git a/Library/Homebrew/cask/lib/hbc/cli/home.rb b/Library/Homebrew/cask/lib/hbc/cli/home.rb index 882cb67af7..15cbbfc8d5 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/home.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/home.rb @@ -1,10 +1,6 @@ module Hbc class CLI - class Home < Base - def self.run(*args) - new(*args).run - end - + class Home < AbstractCommand def run casks = @args.map(&CaskLoader.public_method(:load)) diff --git a/Library/Homebrew/cask/lib/hbc/cli/info.rb b/Library/Homebrew/cask/lib/hbc/cli/info.rb index 327290eea8..6813ad63fa 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/info.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/info.rb @@ -1,6 +1,6 @@ module Hbc class CLI - class Info < Base + class Info < AbstractCommand def self.run(*args) new(*args).run end diff --git a/Library/Homebrew/cask/lib/hbc/cli/install.rb b/Library/Homebrew/cask/lib/hbc/cli/install.rb index 53c5107744..cec4d0f2bd 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/install.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/install.rb @@ -1,6 +1,6 @@ module Hbc class CLI - class Install < Base + class Install < AbstractCommand def self.run(*args) new(*args).run 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 index 89eecd8db6..e3045d2899 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb @@ -1,6 +1,6 @@ module Hbc class CLI - class InternalAppcastCheckpoint < InternalUseBase + class InternalAppcastCheckpoint < AbstractInternalCommand def self.run(*args) new(*args).run end diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb index 371e195709..5bf73135a0 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb @@ -1,6 +1,6 @@ module Hbc class CLI - class InternalAuditModifiedCasks < InternalUseBase + class InternalAuditModifiedCasks < AbstractInternalCommand RELEVANT_STANZAS = [:version, :sha256, :url, :appcast].freeze def self.needs_init? diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_checkurl.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_checkurl.rb index 3cd7add294..06487597ea 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_checkurl.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_checkurl.rb @@ -1,6 +1,6 @@ module Hbc class CLI - class InternalCheckurl < InternalUseBase + class InternalCheckurl < AbstractInternalCommand def self.run(*args) new(*args).run end diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb index e6dc3510ff..2202a737cd 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb @@ -1,6 +1,6 @@ module Hbc class CLI - class InternalDump < InternalUseBase + class InternalDump < AbstractInternalCommand def self.run(*args) new(*args).run end diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_help.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_help.rb index 3903f3b080..3645d91384 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_help.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_help.rb @@ -1,6 +1,6 @@ module Hbc class CLI - class InternalHelp < InternalUseBase + class InternalHelp < AbstractInternalCommand def self.run(*args) new(*args).run end diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb index a60a08d66c..82cf981fdf 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb @@ -1,6 +1,6 @@ module Hbc class CLI - class InternalStanza < InternalUseBase + class InternalStanza < AbstractInternalCommand # Syntax # # brew cask _stanza [ --table | --yaml | --inspect | --quiet ] [ ... ] diff --git a/Library/Homebrew/cask/lib/hbc/cli/list.rb b/Library/Homebrew/cask/lib/hbc/cli/list.rb index f79dc9a54b..884203254b 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/list.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/list.rb @@ -1,6 +1,6 @@ module Hbc class CLI - class List < Base + class List < AbstractCommand def self.run(*args) new(*args).run end diff --git a/Library/Homebrew/cask/lib/hbc/cli/outdated.rb b/Library/Homebrew/cask/lib/hbc/cli/outdated.rb index 8eb387df2d..7a5485344b 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/outdated.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/outdated.rb @@ -1,6 +1,6 @@ module Hbc class CLI - class Outdated < Base + class Outdated < AbstractCommand def self.run(*args) new(*args).run end diff --git a/Library/Homebrew/cask/lib/hbc/cli/search.rb b/Library/Homebrew/cask/lib/hbc/cli/search.rb index 1080538548..3ad1dd4da4 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/search.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb @@ -1,6 +1,6 @@ module Hbc class CLI - class Search < Base + class Search < AbstractCommand def self.run(*args) new(*args).run end diff --git a/Library/Homebrew/cask/lib/hbc/cli/style.rb b/Library/Homebrew/cask/lib/hbc/cli/style.rb index a76c893fce..992e1bb136 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/style.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/style.rb @@ -2,15 +2,11 @@ require "English" module Hbc class CLI - class Style < Base + class Style < AbstractCommand def self.help "checks Cask style using RuboCop" end - def self.run(*args) - new(*args).run - end - attr_reader :args def initialize(*args) @cask_tokens = self.class.cask_tokens_from(args) diff --git a/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb b/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb index 213c5beb6f..dea6a8e5f1 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb @@ -1,6 +1,6 @@ module Hbc class CLI - class Uninstall < Base + class Uninstall < AbstractCommand def self.run(*args) new(*args).run end diff --git a/Library/Homebrew/cask/lib/hbc/cli/zap.rb b/Library/Homebrew/cask/lib/hbc/cli/zap.rb index 26dab15488..df40894afc 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/zap.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/zap.rb @@ -1,6 +1,6 @@ module Hbc class CLI - class Zap < Base + class Zap < AbstractCommand def self.run(*args) new(*args).run end diff --git a/Library/Homebrew/compat/hbc/cli/update.rb b/Library/Homebrew/compat/hbc/cli/update.rb index 7820997cbb..95321e8981 100644 --- a/Library/Homebrew/compat/hbc/cli/update.rb +++ b/Library/Homebrew/compat/hbc/cli/update.rb @@ -1,8 +1,8 @@ -require "cask/lib/hbc/cli/base" +require "cask/lib/hbc/cli/abstract_command" module Hbc class CLI - class Update < Base + class Update < AbstractCommand def self.run(*_ignored) odeprecated "`brew cask update`", "`brew update`", disable_on: Time.utc(2017, 7, 1) result = SystemCommand.run(HOMEBREW_BREW_FILE, args: ["update"],