Skip to content

Commit

Permalink
Parameter :text added to ask() to override I18n prefix.
Browse files Browse the repository at this point in the history
Extend options to include a text variable to override the i18n question
prefix.
  • Loading branch information
simon-soak authored and wjohnstondrip committed May 28, 2019
1 parent 7a14ddb commit 1d3cda0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ gem "capistrano", github: "capistrano/capistrano", require: false

[master]: https://github.com/capistrano/capistrano/compare/v3.11.0...HEAD

* Parameter `:text` added to `ask()` to override I18n question prefix e.g. `ask(:response, 'default_value', {text: 'Ask your question here (default_value): '})` [@simon-soak](https://github.com/simon-soak)
* Your contribution here!

## [`3.11.0`] (2018-06-02)
Expand Down
2 changes: 2 additions & 0 deletions lib/capistrano/configuration/question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def gets
end

def question
custom_text = (options || {})[:text]
return custom_text if custom_text
if default.nil?
I18n.t(:question, key: key, scope: :capistrano)
else
Expand Down
22 changes: 22 additions & 0 deletions spec/lib/capistrano/configuration/question_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,28 @@ class Configuration
end
end

describe "prompt" do
before do
$stdin.expects(:gets).returns("")
end

context "without :text option" do
it "uses i18n" do
$stdout.expects(:print).with("Please enter branch (default): ")
question.call
end
end

context "with :text option" do
let(:options) { { text: "Custom prompt: " } }

it "uses :text value" do
$stdout.expects(:print).with("Custom prompt: ")
question.call
end
end
end

describe "#call" do
context "value is entered" do
let(:branch) { "branch" }
Expand Down

0 comments on commit 1d3cda0

Please sign in to comment.