aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cask/lib
diff options
context:
space:
mode:
authorMarkus Reiter2017-03-08 02:43:22 +0100
committerGitHub2017-03-08 02:43:22 +0100
commitfe694f6db9190239fd4a84f1208d218aa02c0474 (patch)
tree6c5bd9d72442a6dd2eb5214c50570f29dbf330f4 /Library/Homebrew/cask/lib
parent9a4538a3254297f7830afe16ea5a78fb3a9c0146 (diff)
parent3b8524d770172ec4aacb48fceb4dc8d2c1836bce (diff)
downloadbrew-fe694f6db9190239fd4a84f1208d218aa02c0474.tar.bz2
Merge pull request #2284 from reitermarkus/cask-refactor-cli
Refactor CLI options.
Diffstat (limited to 'Library/Homebrew/cask/lib')
-rw-r--r--Library/Homebrew/cask/lib/hbc.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/artifact/binary.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/artifact/pkg.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/cask.rb3
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli.rb35
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/cleanup.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/options.rb39
-rw-r--r--Library/Homebrew/cask/lib/hbc/system_command.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/utils.rb3
10 files changed, 31 insertions, 61 deletions
diff --git a/Library/Homebrew/cask/lib/hbc.rb b/Library/Homebrew/cask/lib/hbc.rb
index 74158b04e..3cdec07d2 100644
--- a/Library/Homebrew/cask/lib/hbc.rb
+++ b/Library/Homebrew/cask/lib/hbc.rb
@@ -21,7 +21,6 @@ require "hbc/fetcher"
require "hbc/installer"
require "hbc/locations"
require "hbc/macos"
-require "hbc/options"
require "hbc/pkg"
require "hbc/qualified_token"
require "hbc/scopes"
@@ -40,7 +39,6 @@ require "utils"
module Hbc
include Locations
include Scopes
- include Options
include Utils
def self.init
diff --git a/Library/Homebrew/cask/lib/hbc/artifact/binary.rb b/Library/Homebrew/cask/lib/hbc/artifact/binary.rb
index 646e5c3ad..9136d6a2a 100644
--- a/Library/Homebrew/cask/lib/hbc/artifact/binary.rb
+++ b/Library/Homebrew/cask/lib/hbc/artifact/binary.rb
@@ -4,7 +4,7 @@ module Hbc
module Artifact
class Binary < Symlinked
def install_phase
- super unless Hbc.no_binaries
+ super if CLI.binaries?
end
end
end
diff --git a/Library/Homebrew/cask/lib/hbc/artifact/pkg.rb b/Library/Homebrew/cask/lib/hbc/artifact/pkg.rb
index 6d6362d46..c43481c82 100644
--- a/Library/Homebrew/cask/lib/hbc/artifact/pkg.rb
+++ b/Library/Homebrew/cask/lib/hbc/artifact/pkg.rb
@@ -48,7 +48,7 @@ module Hbc
"-pkg", source,
"-target", "/"
]
- args << "-verboseR" if Hbc.verbose
+ args << "-verboseR" if CLI.verbose?
args << "-allowUntrusted" if pkg_install_opts :allow_untrusted
with_choices_file do |choices_path|
args << "-applyChoiceChangesXML" << choices_path if choices_path
diff --git a/Library/Homebrew/cask/lib/hbc/cask.rb b/Library/Homebrew/cask/lib/hbc/cask.rb
index 41357760d..52dd676b4 100644
--- a/Library/Homebrew/cask/lib/hbc/cask.rb
+++ b/Library/Homebrew/cask/lib/hbc/cask.rb
@@ -90,8 +90,7 @@ module Hbc
end
def dumpcask
- return unless Hbc.respond_to?(:debug)
- return unless Hbc.debug
+ return unless CLI.debug?
odebug "Cask instance dumps in YAML:"
odebug "Cask instance toplevel:", to_yaml
diff --git a/Library/Homebrew/cask/lib/hbc/cli.rb b/Library/Homebrew/cask/lib/hbc/cli.rb
index afc928bb1..39235fa63 100644
--- a/Library/Homebrew/cask/lib/hbc/cli.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli.rb
@@ -68,13 +68,25 @@ module Hbc
}.freeze
FLAGS = {
- "--no-binaries" => :no_binaries=,
- "--debug" => :debug=,
- "--verbose" => :verbose=,
- "--outdated" => :cleanup_outdated=,
- "--help" => :help=,
+ ["--[no-]binaries", :binaries] => true,
+ ["--debug", :debug] => false,
+ ["--verbose", :verbose] => false,
+ ["--outdated", :outdated] => false,
+ ["--help", :help] => false,
}.freeze
+ FLAGS.each do |(_, method), default_value|
+ instance_variable_set(:"@#{method}", default_value)
+
+ define_singleton_method(:"#{method}=") do |arg|
+ instance_variable_set(:"@#{method}", arg)
+ end
+
+ define_singleton_method(:"#{method}?") do
+ instance_variable_get(:"@#{method}")
+ end
+ end
+
def self.command_classes
@command_classes ||= constants.map(&method(:const_get))
.select { |sym| sym.respond_to?(:run) }
@@ -138,13 +150,13 @@ module Hbc
command_string, *rest = *arguments
rest = process_options(rest)
- command = Hbc.help ? "help" : lookup_command(command_string)
+ command = help? ? "help" : lookup_command(command_string)
Hbc.default_tap.install unless Hbc.default_tap.installed?
Hbc.init if should_init?(command)
run_command(command, *rest)
rescue CaskError, CaskSha256MismatchError, ArgumentError => e
msg = e.message
- msg << e.backtrace.join("\n") if Hbc.debug
+ msg << e.backtrace.join("\n") if debug?
onoe msg
exit 1
rescue StandardError, ScriptError, NoMemoryError => e
@@ -194,9 +206,9 @@ module Hbc
EOS
end
- FLAGS.each do |flag, method|
- opts.on(flag) do
- Hbc.public_send(method, true)
+ FLAGS.keys.each do |flag, method|
+ opts.on(flag) do |bool|
+ send(:"#{method}=", bool)
end
end
@@ -224,7 +236,8 @@ module Hbc
end
# for compat with Homebrew, not certain if this is desirable
- Hbc.verbose = true if !ENV["VERBOSE"].nil? || !ENV["HOMEBREW_VERBOSE"].nil?
+ self.verbose = true if ARGV.verbose?
+ self.debug = true if ARGV.debug?
remaining
end
diff --git a/Library/Homebrew/cask/lib/hbc/cli/cleanup.rb b/Library/Homebrew/cask/lib/hbc/cli/cleanup.rb
index 0bb3c3694..9ebccabd0 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/cleanup.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/cleanup.rb
@@ -21,7 +21,7 @@ module Hbc
end
def self.default
- @default ||= new(Hbc.cache, Hbc.cleanup_outdated)
+ @default ||= new(Hbc.cache, CLI.outdated?)
end
attr_reader :cache_location, :outdated_only
diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb
index ac1b20493..36a1ca74b 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb
@@ -12,7 +12,7 @@ module Hbc
end
def self.dump_casks(*cask_tokens)
- Hbc.debug = true # Yuck. At the moment this is the only way to make dumps visible
+ CLI.debug = true # Yuck. At the moment this is the only way to make dumps visible
count = 0
cask_tokens.each do |cask_token|
begin
diff --git a/Library/Homebrew/cask/lib/hbc/options.rb b/Library/Homebrew/cask/lib/hbc/options.rb
deleted file mode 100644
index e9ba54ff6..000000000
--- a/Library/Homebrew/cask/lib/hbc/options.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-module Hbc
- module Options
- def self.included(base)
- base.extend(ClassMethods)
- end
-
- module ClassMethods
- attr_writer :no_binaries
-
- def no_binaries
- @no_binaries ||= false
- end
-
- attr_writer :debug
-
- def debug
- @debug ||= false
- end
-
- attr_writer :verbose
-
- def verbose
- @verbose ||= false
- end
-
- attr_writer :cleanup_outdated
-
- def cleanup_outdated
- @cleanup_outdated ||= false
- end
-
- attr_writer :help
-
- def help
- @help ||= false
- end
- end
- end
-end
diff --git a/Library/Homebrew/cask/lib/hbc/system_command.rb b/Library/Homebrew/cask/lib/hbc/system_command.rb
index f26be8e62..17658bdfa 100644
--- a/Library/Homebrew/cask/lib/hbc/system_command.rb
+++ b/Library/Homebrew/cask/lib/hbc/system_command.rb
@@ -154,7 +154,7 @@ module Hbc
def self._parse_plist(command, output)
raise CaskError, "Empty plist input" unless output =~ /\S/
output.sub!(/\A(.*?)(<\?\s*xml)/m, '\2')
- _warn_plist_garbage(command, Regexp.last_match[1]) if Hbc.debug
+ _warn_plist_garbage(command, Regexp.last_match[1]) if CLI.debug?
output.sub!(%r{(<\s*/\s*plist\s*>)(.*?)\Z}m, '\1')
_warn_plist_garbage(command, Regexp.last_match[2])
xml = Plist.parse_xml(output)
diff --git a/Library/Homebrew/cask/lib/hbc/utils.rb b/Library/Homebrew/cask/lib/hbc/utils.rb
index 7bfc4ea42..3fc817dd5 100644
--- a/Library/Homebrew/cask/lib/hbc/utils.rb
+++ b/Library/Homebrew/cask/lib/hbc/utils.rb
@@ -30,8 +30,7 @@ end
# global methods
def odebug(title, *sput)
- return unless Hbc.respond_to?(:debug)
- return unless Hbc.debug
+ return unless Hbc::CLI.debug?
puts Formatter.headline(title, color: :magenta)
puts sput unless sput.empty?
end