Merge pull request #2729 from reitermarkus/cask-require-sha
Fix parsing `--require-sha` and `HOMEBREW_CASK_OPTS`.
This commit is contained in:
commit
e2e578fd83
@ -92,10 +92,10 @@ module Hbc
|
|||||||
command.is_a?(Class) && !command.abstract? && command.needs_init?
|
command.is_a?(Class) && !command.abstract? && command.needs_init?
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.run_command(command, *rest)
|
def self.run_command(command, *args)
|
||||||
if command.respond_to?(:run)
|
if command.respond_to?(:run)
|
||||||
# usual case: built-in command verb
|
# usual case: built-in command verb
|
||||||
command.run(*rest)
|
command.run(*args)
|
||||||
elsif require?(which("brewcask-#{command}.rb"))
|
elsif require?(which("brewcask-#{command}.rb"))
|
||||||
# external command as Ruby library on PATH, Homebrew-style
|
# external command as Ruby library on PATH, Homebrew-style
|
||||||
elsif command.to_s.include?("/") && require?(command.to_s)
|
elsif command.to_s.include?("/") && require?(command.to_s)
|
||||||
@ -111,7 +111,7 @@ module Hbc
|
|||||||
if klass.respond_to?(:run)
|
if klass.respond_to?(:run)
|
||||||
# invoke "run" on a Ruby library which follows our coding conventions
|
# invoke "run" on a Ruby library which follows our coding conventions
|
||||||
# other Ruby libraries must do everything via "require"
|
# other Ruby libraries must do everything via "require"
|
||||||
klass.run(*rest)
|
klass.run(*args)
|
||||||
end
|
end
|
||||||
elsif which("brewcask-#{command}")
|
elsif which("brewcask-#{command}")
|
||||||
# arbitrary external executable on PATH, Homebrew-style
|
# arbitrary external executable on PATH, Homebrew-style
|
||||||
@ -124,7 +124,7 @@ module Hbc
|
|||||||
exec command, *ARGV[1..-1]
|
exec command, *ARGV[1..-1]
|
||||||
else
|
else
|
||||||
# failure
|
# failure
|
||||||
NullCommand.new(command).run
|
NullCommand.new(command, *args).run
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -136,9 +136,30 @@ module Hbc
|
|||||||
@args = process_options(*args)
|
@args = process_options(*args)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def detect_command_and_arguments(*args)
|
||||||
|
command = args.detect do |arg|
|
||||||
|
if self.class.commands.include?(arg)
|
||||||
|
true
|
||||||
|
else
|
||||||
|
break unless arg.start_with?("-")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if index = args.index(command)
|
||||||
|
args.delete_at(index)
|
||||||
|
end
|
||||||
|
|
||||||
|
[*command, *args]
|
||||||
|
end
|
||||||
|
|
||||||
def run
|
def run
|
||||||
command_name, *args = *@args
|
command_name, *args = detect_command_and_arguments(*@args)
|
||||||
command = help? ? "help" : self.class.lookup_command(command_name)
|
command = if help?
|
||||||
|
args.unshift(command_name)
|
||||||
|
"help"
|
||||||
|
else
|
||||||
|
self.class.lookup_command(command_name)
|
||||||
|
end
|
||||||
|
|
||||||
MacOS.full_version = ENV["MACOS_VERSION"] unless ENV["MACOS_VERSION"].nil?
|
MacOS.full_version = ENV["MACOS_VERSION"] unless ENV["MACOS_VERSION"].nil?
|
||||||
|
|
||||||
@ -147,7 +168,7 @@ module Hbc
|
|||||||
self.class.run_command(command, *args)
|
self.class.run_command(command, *args)
|
||||||
rescue CaskError, CaskSha256MismatchError, ArgumentError, OptionParser::InvalidOption => e
|
rescue CaskError, CaskSha256MismatchError, ArgumentError, OptionParser::InvalidOption => e
|
||||||
msg = e.message
|
msg = e.message
|
||||||
msg << e.backtrace.join("\n") if ARGV.debug?
|
msg << e.backtrace.join("\n").prepend("\n") if ARGV.debug?
|
||||||
onoe msg
|
onoe msg
|
||||||
exit 1
|
exit 1
|
||||||
rescue StandardError, ScriptError, NoMemoryError => e
|
rescue StandardError, ScriptError, NoMemoryError => e
|
||||||
@ -199,18 +220,19 @@ module Hbc
|
|||||||
end
|
end
|
||||||
|
|
||||||
class NullCommand
|
class NullCommand
|
||||||
def initialize(attempted_verb)
|
def initialize(command, *args)
|
||||||
@attempted_verb = attempted_verb
|
@command = command
|
||||||
|
@args = args
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(*_args)
|
def run(*_args)
|
||||||
purpose
|
purpose
|
||||||
usage
|
usage
|
||||||
|
|
||||||
return if @attempted_verb.to_s.strip.empty?
|
return if @command == "help" && @args.empty?
|
||||||
return if @attempted_verb == "help"
|
|
||||||
|
|
||||||
raise ArgumentError, "Unknown command: #{@attempted_verb}"
|
unknown_command = @args.empty? ? @command : @args.first
|
||||||
|
raise ArgumentError, "Unknown command: #{unknown_command}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def purpose
|
def purpose
|
||||||
|
|||||||
@ -9,6 +9,7 @@ module Hbc
|
|||||||
option "--debug", :debug, false
|
option "--debug", :debug, false
|
||||||
option "--verbose", :verbose, false
|
option "--verbose", :verbose, false
|
||||||
option "--outdated", :outdated_only, false
|
option "--outdated", :outdated_only, false
|
||||||
|
option "--require-sha", :require_sha, false
|
||||||
|
|
||||||
def self.command_name
|
def self.command_name
|
||||||
@command_name ||= name.sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1_\2').downcase
|
@command_name ||= name.sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1_\2').downcase
|
||||||
|
|||||||
@ -3,7 +3,6 @@ module Hbc
|
|||||||
class Install < AbstractCommand
|
class Install < AbstractCommand
|
||||||
option "--force", :force, false
|
option "--force", :force, false
|
||||||
option "--skip-cask-deps", :skip_cask_deps, false
|
option "--skip-cask-deps", :skip_cask_deps, false
|
||||||
option "--require-sha", :require_sha, false
|
|
||||||
|
|
||||||
def initialize(*)
|
def initialize(*)
|
||||||
super
|
super
|
||||||
|
|||||||
@ -1,10 +1,6 @@
|
|||||||
module Hbc
|
module Hbc
|
||||||
class CLI
|
class CLI
|
||||||
class Search < AbstractCommand
|
class Search < AbstractCommand
|
||||||
def initialize(*args)
|
|
||||||
@args = args
|
|
||||||
end
|
|
||||||
|
|
||||||
def run
|
def run
|
||||||
results = self.class.search(*args)
|
results = self.class.search(*args)
|
||||||
self.class.render_results(*results)
|
self.class.render_results(*results)
|
||||||
|
|||||||
@ -27,6 +27,7 @@ module Hbc
|
|||||||
# TODO: speed up Hbc::Source::Tapped (main perf drag is calling Hbc.all_tokens repeatedly)
|
# TODO: speed up Hbc::Source::Tapped (main perf drag is calling Hbc.all_tokens repeatedly)
|
||||||
# TODO: ability to specify expected source when calling CaskLoader.load (minor perf benefit)
|
# TODO: ability to specify expected source when calling CaskLoader.load (minor perf benefit)
|
||||||
Pathname.glob(caskroom.join("*"))
|
Pathname.glob(caskroom.join("*"))
|
||||||
|
.sort
|
||||||
.map do |caskroom_path|
|
.map do |caskroom_path|
|
||||||
token = caskroom_path.basename.to_s
|
token = caskroom_path.basename.to_s
|
||||||
|
|
||||||
|
|||||||
@ -42,7 +42,7 @@ describe Hbc::CLI, :cask do
|
|||||||
|
|
||||||
it "prints help output when subcommand receives `--help` flag" do
|
it "prints help output when subcommand receives `--help` flag" do
|
||||||
command = Hbc::CLI.new("noop", "--help")
|
command = Hbc::CLI.new("noop", "--help")
|
||||||
expect(described_class).to receive(:run_command).with("help")
|
expect(described_class).to receive(:run_command).with("help", "noop")
|
||||||
command.run
|
command.run
|
||||||
expect(command.help?).to eq(true)
|
expect(command.help?).to eq(true)
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user