diff --git a/CHANGELOG.md b/CHANGELOG.md index e9f30daf..52b18472 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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` diff --git a/capistrano.gemspec b/capistrano.gemspec index 0fe2d29a..4558e1d4 100644 --- a/capistrano.gemspec +++ b/capistrano.gemspec @@ -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' diff --git a/lib/capistrano/all.rb b/lib/capistrano/all.rb index 40b1c5c6..82bb191a 100644 --- a/lib/capistrano/all.rb +++ b/lib/capistrano/all.rb @@ -1,7 +1,7 @@ require 'rake' require 'sshkit' require 'sshkit/dsl' -require 'highline' +require 'io/console' Rake.application.options.trace = true diff --git a/lib/capistrano/configuration/question.rb b/lib/capistrano/configuration/question.rb index 84a48c30..1fc19291 100644 --- a/lib/capistrano/configuration/question.rb +++ b/lib/capistrano/configuration/question.rb @@ -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 diff --git a/spec/lib/capistrano/configuration/question_spec.rb b/spec/lib/capistrano/configuration/question_spec.rb index 40b847db..709e98c6 100644 --- a/spec/lib/capistrano/configuration/question_spec.rb +++ b/spec/lib/capistrano/configuration/question_spec.rb @@ -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