Skip to content

Commit 9942ff7

Browse files
deivid-rodriguezhsbt
authored andcommitted
[rubygems/rubygems] Use shorter questions as prompts in bundle gem
If we use long explanations as prompts, sometimes the prompt gets printed twice due to a (I think) reline/readline bug. ruby/rubygems@987e0dfa90
1 parent 9b0f9f8 commit 9942ff7

3 files changed

Lines changed: 14 additions & 11 deletions

File tree

lib/bundler/cli/gem.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,13 @@ def resolve_name(name)
279279
SharedHelpers.pwd.join(name).basename.to_s
280280
end
281281

282-
def ask_and_set(key, header, message)
282+
def ask_and_set(key, prompt, explanation)
283283
choice = options[key]
284284
choice = Bundler.settings["gem.#{key}"] if choice.nil?
285285

286286
if choice.nil?
287-
Bundler.ui.confirm header
288-
choice = Bundler.ui.yes? "#{message} y/(n):"
287+
Bundler.ui.info explanation
288+
choice = Bundler.ui.yes? "#{prompt} y/(n):"
289289
Bundler.settings.set_global("gem.#{key}", choice)
290290
end
291291

@@ -307,7 +307,7 @@ def ask_and_set_test_framework
307307
test_framework = options[:test] || Bundler.settings["gem.test"]
308308

309309
if test_framework.to_s.empty?
310-
Bundler.ui.confirm "Do you want to generate tests with your gem?"
310+
Bundler.ui.info "Do you want to generate tests with your gem?"
311311
Bundler.ui.info hint_text("test")
312312

313313
result = Bundler.ui.ask "Enter a test framework. rspec/minitest/test-unit/(none):"
@@ -347,7 +347,7 @@ def ask_and_set_ci
347347
ci_template = options[:ci] || Bundler.settings["gem.ci"]
348348

349349
if ci_template.to_s.empty?
350-
Bundler.ui.confirm "Do you want to set up continuous integration for your gem? " \
350+
Bundler.ui.info "Do you want to set up continuous integration for your gem? " \
351351
"Supported services:\n" \
352352
"* CircleCI: https://circleci.com/\n" \
353353
"* GitHub Actions: https://github.com/features/actions\n" \
@@ -380,7 +380,7 @@ def ask_and_set_linter
380380
linter_template = deprecated_rubocop_option if linter_template.nil?
381381

382382
if linter_template.to_s.empty?
383-
Bundler.ui.confirm "Do you want to add a code linter and formatter to your gem? " \
383+
Bundler.ui.info "Do you want to add a code linter and formatter to your gem? " \
384384
"Supported Linters:\n" \
385385
"* RuboCop: https://rubocop.org\n" \
386386
"* Standard: https://github.com/standardrb/standard\n" \

lib/bundler/ui/shell.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ def quiet?
8080
end
8181

8282
def ask(msg)
83-
@shell.ask(msg)
83+
@shell.ask(msg, :green)
8484
end
8585

8686
def yes?(msg)
87-
@shell.yes?(msg)
87+
@shell.yes?(msg, :green)
8888
end
8989

9090
def no?(msg)

spec/bundler/commands/newgem_spec.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,7 +1939,7 @@ def create_temporary_dir(dir)
19391939
expect(bundled_app("foobar/.github/workflows/main.yml")).to exist
19401940
end
19411941

1942-
it "asks about MIT license" do
1942+
it "asks about MIT license just once" do
19431943
global_config "BUNDLE_GEM__MIT" => nil
19441944

19451945
bundle "config list"
@@ -1949,26 +1949,29 @@ def create_temporary_dir(dir)
19491949
end
19501950

19511951
expect(bundled_app("foobar/LICENSE.txt")).to exist
1952+
expect(out).to include("Using a MIT license means").once
19521953
end
19531954

1954-
it "asks about CoC" do
1955+
it "asks about CoC just once" do
19551956
global_config "BUNDLE_GEM__COC" => nil
19561957

19571958
bundle "gem foobar" do |input, _, _|
19581959
input.puts "yes"
19591960
end
19601961

19611962
expect(bundled_app("foobar/CODE_OF_CONDUCT.md")).to exist
1963+
expect(out).to include("Codes of conduct can increase contributions to your project").once
19621964
end
19631965

1964-
it "asks about CHANGELOG" do
1966+
it "asks about CHANGELOG just once" do
19651967
global_config "BUNDLE_GEM__CHANGELOG" => nil
19661968

19671969
bundle "gem foobar" do |input, _, _|
19681970
input.puts "yes"
19691971
end
19701972

19711973
expect(bundled_app("foobar/CHANGELOG.md")).to exist
1974+
expect(out).to include("A changelog is a file which contains").once
19721975
end
19731976
end
19741977

0 commit comments

Comments
 (0)