mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
Merge pull request #1112 from kaikuchn/master
removed HighLine in favor of ruby's noecho
This commit is contained in:
commit
b372e58ffc
5 changed files with 29 additions and 47 deletions
|
@ -14,8 +14,7 @@ https://github.com/capistrano/capistrano/compare/v3.2.1...HEAD
|
|||
* Added tests for after/before hooks features (@juanibiapina, @miry)
|
||||
* Improved the output of `cap --help`. (@mbrictson)
|
||||
* Cucumber suite now runs on the latest version of Vagrant (@tpett)
|
||||
* The `ask` method now supports the `echo: false` option. (@mbrictson)
|
||||
* Capistrano now depends on the `highline` gem.
|
||||
* The `ask` method now supports the `echo: false` option. (@mbrictson, @kaikuchn)
|
||||
|
||||
## `3.2.1`
|
||||
|
||||
|
|
|
@ -28,7 +28,6 @@ eos
|
|||
gem.add_dependency 'sshkit', '~> 1.3'
|
||||
gem.add_dependency 'rake', '>= 10.0.0'
|
||||
gem.add_dependency 'i18n'
|
||||
gem.add_dependency 'highline'
|
||||
|
||||
gem.add_development_dependency 'rspec'
|
||||
gem.add_development_dependency 'mocha'
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'rake'
|
||||
require 'sshkit'
|
||||
require 'sshkit/dsl'
|
||||
require 'highline'
|
||||
require 'io/console'
|
||||
|
||||
Rake.application.options.trace = true
|
||||
|
||||
|
|
|
@ -7,18 +7,22 @@ module Capistrano
|
|||
end
|
||||
|
||||
def call
|
||||
response = highline_ask(question) { |q| q.echo = echo? }
|
||||
save_response(value_or_default(response))
|
||||
ask_question
|
||||
save_response
|
||||
end
|
||||
|
||||
private
|
||||
attr_reader :env, :key, :default, :options
|
||||
|
||||
def save_response(value)
|
||||
env.set(key, value)
|
||||
def ask_question
|
||||
$stdout.print question
|
||||
end
|
||||
|
||||
def value_or_default(response)
|
||||
def save_response
|
||||
env.set(key, value_or_default)
|
||||
end
|
||||
|
||||
def value_or_default
|
||||
if response.empty?
|
||||
default
|
||||
else
|
||||
|
@ -26,6 +30,12 @@ module Capistrano
|
|||
end
|
||||
end
|
||||
|
||||
def response
|
||||
return @response if defined? @response
|
||||
return @response = $stdin.gets.chomp if echo?
|
||||
@response = $stdin.noecho(&:gets).chomp
|
||||
end
|
||||
|
||||
def question
|
||||
I18n.t(:question, key: key, default_value: default, scope: :capistrano)
|
||||
end
|
||||
|
@ -33,12 +43,6 @@ module Capistrano
|
|||
def echo?
|
||||
(options || {}).fetch(:echo, true)
|
||||
end
|
||||
|
||||
def highline_ask(question, &block)
|
||||
# For compatibility, we call #to_s to unwrap HighLine::String and
|
||||
# return a regular String.
|
||||
HighLine.new.ask(question, &block).to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,6 +6,7 @@ module Capistrano
|
|||
describe Question do
|
||||
|
||||
let(:question) { Question.new(env, key, default, options) }
|
||||
let(:question_without_echo) { Question.new(env, key, default, echo: false) }
|
||||
let(:default) { :default }
|
||||
let(:key) { :branch }
|
||||
let(:env) { stub }
|
||||
|
@ -18,20 +19,27 @@ module Capistrano
|
|||
end
|
||||
|
||||
describe '#call' do
|
||||
subject { question.call }
|
||||
|
||||
context 'value is entered' do
|
||||
let(:branch) { 'branch' }
|
||||
|
||||
before do
|
||||
$stdout.expects(:print).with('Please enter branch (default): ')
|
||||
$stdin.expects(:gets).returns(branch)
|
||||
end
|
||||
|
||||
it 'sets the value' do
|
||||
it 'sets the echoed value' do
|
||||
$stdin.expects(:gets).returns(branch)
|
||||
$stdin.expects(:noecho).never
|
||||
env.expects(:set).with(key, branch)
|
||||
|
||||
question.call
|
||||
end
|
||||
|
||||
it 'sets the value but does not echo it' do
|
||||
$stdin.expects(:noecho).returns(branch)
|
||||
env.expects(:set).with(key, branch)
|
||||
|
||||
question_without_echo.call
|
||||
end
|
||||
end
|
||||
|
||||
context 'value is not entered' do
|
||||
|
@ -46,34 +54,6 @@ module Capistrano
|
|||
env.expects(:set).with(key, branch)
|
||||
question.call
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'highline behavior' do
|
||||
let(:highline) { stub }
|
||||
|
||||
before do
|
||||
question.expects(:highline_ask).yields(highline).returns("answer")
|
||||
env.expects(:set).with(key, "answer")
|
||||
end
|
||||
|
||||
context 'with no options' do
|
||||
let(:options) { nil }
|
||||
|
||||
it 'passes echo: true to HighLine' do
|
||||
highline.expects(:"echo=").with(true)
|
||||
question.call
|
||||
end
|
||||
end
|
||||
|
||||
context 'with echo: false' do
|
||||
let(:options) { { echo: false } }
|
||||
|
||||
it 'passes echo: false to HighLine' do
|
||||
highline.expects(:"echo=").with(false)
|
||||
question.call
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue