Move brew cask --version into separate file.
This commit is contained in:
parent
ef02414888
commit
b24dc2268a
@ -19,6 +19,7 @@ require "hbc/cli/reinstall"
|
|||||||
require "hbc/cli/search"
|
require "hbc/cli/search"
|
||||||
require "hbc/cli/style"
|
require "hbc/cli/style"
|
||||||
require "hbc/cli/uninstall"
|
require "hbc/cli/uninstall"
|
||||||
|
require "hbc/cli/--version"
|
||||||
require "hbc/cli/zap"
|
require "hbc/cli/zap"
|
||||||
|
|
||||||
require "hbc/cli/internal_use_base"
|
require "hbc/cli/internal_use_base"
|
||||||
@ -116,7 +117,7 @@ module Hbc
|
|||||||
elsif command.to_s.include?("/") && require?(command.to_s)
|
elsif command.to_s.include?("/") && require?(command.to_s)
|
||||||
# external command as Ruby library with literal path, useful
|
# external command as Ruby library with literal path, useful
|
||||||
# for development and troubleshooting
|
# for development and troubleshooting
|
||||||
sym = Pathname.new(command.to_s).basename(".rb").to_s.capitalize
|
sym = File.basename(command.to_s, ".rb").capitalize
|
||||||
klass = begin
|
klass = begin
|
||||||
const_get(sym)
|
const_get(sym)
|
||||||
rescue NameError
|
rescue NameError
|
||||||
@ -247,16 +248,14 @@ module Hbc
|
|||||||
@attempted_verb = attempted_verb
|
@attempted_verb = attempted_verb
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(*args)
|
def run(*_args)
|
||||||
if args.include?("--version") || @attempted_verb == "--version"
|
purpose
|
||||||
puts Hbc.full_version
|
usage
|
||||||
else
|
|
||||||
purpose
|
return if @attempted_verb.to_s.strip.empty?
|
||||||
usage
|
return if @attempted_verb == "help"
|
||||||
unless @attempted_verb.to_s.strip.empty? || @attempted_verb == "help"
|
|
||||||
raise CaskError, "Unknown command: #{@attempted_verb}"
|
raise ArgumentError, "Unknown command: #{@attempted_verb}"
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def purpose
|
def purpose
|
||||||
|
|||||||
18
Library/Homebrew/cask/lib/hbc/cli/--version.rb
Normal file
18
Library/Homebrew/cask/lib/hbc/cli/--version.rb
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
module Hbc
|
||||||
|
class CLI
|
||||||
|
class Version < Base
|
||||||
|
def self.command_name
|
||||||
|
"--#{super}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.run(*args)
|
||||||
|
raise ArgumentError, "#{command_name} does not take arguments." unless args.empty?
|
||||||
|
puts Hbc.full_version
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.help
|
||||||
|
"displays the Homebrew-Cask version"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
13
Library/Homebrew/test/cask/cli/--version_spec.rb
Normal file
13
Library/Homebrew/test/cask/cli/--version_spec.rb
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
describe Hbc::CLI::Version, :cask do
|
||||||
|
describe "::run" do
|
||||||
|
it "outputs the current Hombrew-Cask version" do
|
||||||
|
expect { described_class.run }
|
||||||
|
.to output(/\AHomebrew-Cask.*\d+\.\d+\.\d+/).to_stdout
|
||||||
|
.and not_to_output.to_stderr
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does not support arguments" do
|
||||||
|
expect { described_class.run(:foo, :bar) }.to raise_error(ArgumentError)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -1,9 +0,0 @@
|
|||||||
describe "brew cask --version", :cask do
|
|
||||||
it "respects the --version argument" do
|
|
||||||
expect {
|
|
||||||
expect {
|
|
||||||
Hbc::CLI::NullCommand.new("--version").run
|
|
||||||
}.not_to output.to_stderr
|
|
||||||
}.to output(Hbc.full_version).to_stdout
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -27,8 +27,10 @@ describe Hbc::CLI, :cask do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "passes `--version` along to the subcommand" do
|
it "passes `--version` along to the subcommand" do
|
||||||
expect(described_class).to receive(:run_command).with(noop_command, "--version")
|
version_command = double("CLI::Version")
|
||||||
described_class.process(%w[noop --version])
|
allow(described_class).to receive(:lookup_command).with("--version").and_return(version_command)
|
||||||
|
expect(described_class).to receive(:run_command).with(version_command)
|
||||||
|
described_class.process(["--version"])
|
||||||
end
|
end
|
||||||
|
|
||||||
it "prints help output when subcommand receives `--help` flag" do
|
it "prints help output when subcommand receives `--help` flag" do
|
||||||
|
|||||||
@ -112,4 +112,5 @@ RSpec.configure do |config|
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
RSpec::Matchers.define_negated_matcher :not_to_output, :output
|
||||||
RSpec::Matchers.alias_matcher :have_failed, :be_failed
|
RSpec::Matchers.alias_matcher :have_failed, :be_failed
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
require "open3"
|
require "open3"
|
||||||
|
|
||||||
RSpec::Matchers.define_negated_matcher :not_to_output, :output
|
|
||||||
RSpec::Matchers.define_negated_matcher :be_a_failure, :be_a_success
|
RSpec::Matchers.define_negated_matcher :be_a_failure, :be_a_success
|
||||||
|
|
||||||
RSpec.shared_context "integration test" do
|
RSpec.shared_context "integration test" do
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user