From 7061b06fd87dc8b952f9072507ee991ee0a0858e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Wed, 6 Nov 2019 12:45:52 +0100 Subject: [PATCH] Lazily require `readline` The current implementation of readline has issues under Windows, and those issues prevent thor from being used. For example, in our bundler Windows CI, we had to patch `rb-readline` to workaround some issues because `rb-readline` (the default `readline` provider on Windows) couldn't be required. Moreover, we still get some issues when requiring `rb-readline` like ``` HOME environment variable (or HOMEDRIVE and HOMEPATH) must be set and point to a directory ``` Since in some situations the part of thor using `readline` (`Thor::LineEditor`) is not required, for example, in most of CI situations. I thought it could be a good idea to lazily require `readline`. --- lib/thor/line_editor/readline.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/thor/line_editor/readline.rb b/lib/thor/line_editor/readline.rb index e4a2c44c3..4631fe884 100644 --- a/lib/thor/line_editor/readline.rb +++ b/lib/thor/line_editor/readline.rb @@ -1,12 +1,12 @@ -begin - require "readline" -rescue LoadError -end - class Thor module LineEditor class Readline < Basic def self.available? + begin + require "readline" + rescue LoadError + end + Object.const_defined?(:Readline) end