aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cask/lib/hbc/cli.rb
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/hbc/cli.rb
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/hbc/cli.rb')
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli.rb35
1 files changed, 24 insertions, 11 deletions
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