Module: ThorRepl

Defined in:
lib/thor_repl.rb,
lib/thor_repl/looper.rb,
lib/thor_repl/history.rb,
lib/thor_repl/version.rb

Defined Under Namespace

Classes: History, Looper

Constant Summary collapse

HISTORY_FILE_PATH =
ENV.fetch("THOR_REPL_HISTORY_FILE", "~/.thor_repl_history")
VERSION =
"0.1.4"

Class Method Summary collapse

Class Method Details

.load_readlineObject



22
23
24
25
26
27
28
29
30
# File 'lib/thor_repl.rb', line 22

def self.load_readline
  require 'readline'
  ::Readline
rescue LoadError
  raise "Sorry, you can't use Thor REPL without Readline or a compatible library. \n" \
    "Possible solutions: \n" \
    " * Rebuild Ruby with Readline support using `--with-readline` \n" \
    " * Use the rb-readline gem, which is a pure-Ruby port of Readline \n" \
end

.start(thor_commands_class, history: true, prompt: ">", history_file_path: HISTORY_FILE_PATH) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/thor_repl.rb', line 8

def self.start(thor_commands_class, history: true, prompt: ">", history_file_path: HISTORY_FILE_PATH)
  load_readline

  looper = Looper.new(thor_commands_class: thor_commands_class, prompt: prompt)

  if history
    History.with_history(history_file_path: history_file_path) do
      looper.run
    end
  else
    looper.run
  end
end