diff options
Diffstat (limited to 'Library/Homebrew/cask/lib/hbc/cli.rb')
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cli.rb | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/cli.rb b/Library/Homebrew/cask/lib/hbc/cli.rb index 102446ea4..3176489cb 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) } @@ -91,17 +103,6 @@ module Hbc @lookup.fetch(command_string, command_string) end - # modified from Homebrew - def self.require?(path) - require path - true # OK if already loaded - rescue LoadError => e - # HACK: :( because we should raise on syntax errors - # but not if the file doesn't exist. - # TODO: make robust! - raise unless e.to_s.include? path - end - def self.should_init?(command) (command.is_a? Class) && (command < CLI::Base) && command.needs_init? end @@ -149,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 @@ -205,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 @@ -235,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 |
