From fe3c9308638780a598afc52b557c4317f7f64def Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Mon, 11 Nov 2019 21:05:50 +0100 Subject: [PATCH] Restore old 1.8.7 check on completion_proc= `rb-readline`, the default readline implementation that currently comes with Windows, does not allow `nil` to be passed in here because it doesn't respond to `call`. See: https://github.com/ConnorAtherton/rb-readline/blob/9fba246073f78831b7c7129c76cc07d8476a8892/lib/readline.rb#L91-L97 --- lib/thor/line_editor/readline.rb | 5 ++++- spec/line_editor/readline_spec.rb | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/thor/line_editor/readline.rb b/lib/thor/line_editor/readline.rb index 4631fe884..2fd925d96 100644 --- a/lib/thor/line_editor/readline.rb +++ b/lib/thor/line_editor/readline.rb @@ -13,7 +13,10 @@ def self.available? def readline if echo? ::Readline.completion_append_character = nil - ::Readline.completion_proc = completion_proc + # rb-readline does not allow Readline.completion_proc= to receive nil. + if complete = completion_proc + ::Readline.completion_proc = complete + end ::Readline.readline(prompt, add_to_history?) else super diff --git a/spec/line_editor/readline_spec.rb b/spec/line_editor/readline_spec.rb index df426d3b4..86cf7466e 100644 --- a/spec/line_editor/readline_spec.rb +++ b/spec/line_editor/readline_spec.rb @@ -23,14 +23,14 @@ describe "#readline" do it "invokes the readline library" do expect(::Readline).to receive(:readline).with("> ", true).and_return("foo") - expect(::Readline).to receive(:completion_proc=) + expect(::Readline).to_not receive(:completion_proc=) editor = Thor::LineEditor::Readline.new("> ", {}) expect(editor.readline).to eq("foo") end it "supports the add_to_history option" do expect(::Readline).to receive(:readline).with("> ", false).and_return("foo") - expect(::Readline).to receive(:completion_proc=) + expect(::Readline).to_not receive(:completion_proc=) editor = Thor::LineEditor::Readline.new("> ", :add_to_history => false) expect(editor.readline).to eq("foo") end