1
0
Fork 0
mirror of https://github.com/capistrano/capistrano synced 2023-03-27 23:21:18 -04:00

--version Prints Both Cap and Rake versions.

Small modification, shows a proof of concept on how we can enable other
top-level command line flags by interacting with Rake (they could make this
easier, to be honest).

Two pending tests for a `--trace` option and a `--format` option, I'm not
fixed on these names, but the notion stands.
This commit is contained in:
Lee Hambley 2013-06-13 16:12:10 +02:00
parent 43179a7c67
commit 046115272f
2 changed files with 61 additions and 0 deletions

View file

@ -11,6 +11,14 @@ module Capistrano
super
end
def standard_rake_options
Rake::Application.new.standard_rake_options.tap do |sra|
sra[sra.index { |opt| opt[0] == "--version" }][3] = lambda do |value|
puts "Capistrano Version: #{Capistrano::VERSION} (Rake Version: #{RAKEVERSION})"
end
end
end
def load_rakefile
@name = 'cap'
super

View file

@ -0,0 +1,53 @@
require 'spec_helper'
describe Capistrano::Application do
it "provides a --trace option which enables SSHKit/NetSSH trace output"
it "provides a --format option which enables the choice of output formatting"
it "overrides the rake method, but still prints the rake version" do
out, _ = capture_io do
flags '--version', '-V'
end
out.should match(/\bCapistrano Version\b/)
out.should match(/\b#{Capistrano::VERSION}\b/)
out.should match(/\bRake Version\b/)
out.should match(/\b#{RAKEVERSION}\b/)
end
def flags(*sets)
sets.each do |set|
ARGV.clear
@exit = catch(:system_exit) { command_line(*set) }
end
yield(subject.options) if block_given?
end
def command_line(*options)
options.each { |opt| ARGV << opt }
def subject.exit(*args)
throw(:system_exit, :exit)
end
subject.instance_eval do
handle_options
end
subject.options
end
def capture_io
require 'stringio'
orig_stdout, orig_stderr = $stdout, $stderr
captured_stdout, captured_stderr = StringIO.new, StringIO.new
$stdout, $stderr = captured_stdout, captured_stderr
yield
return captured_stdout.string, captured_stderr.string
ensure
$stdout = orig_stdout
$stderr = orig_stderr
end
end