Class: Playtypus::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/playtypus/cli.rb

Instance Method Summary collapse

Instance Method Details

#play(*args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/playtypus/cli.rb', line 13

def play(*args)
  require_relative '../../ascii.rb'
  $logger.debug "playtypus is playing with options #{options.inspect}"
  
  sender = Playtypus::HttpSender.new(options[:host])
  preserve_times = options[:preserve_times]
  calls = []

  if File.directory? options[:call_log]
    $logger.info "--call-log is a directory.  calls will be sent in order, without --preserve-times"
    preserve_times = false
    logs = Dir.glob("#{options[:call_log]}/**/*.json")
    logs.sort.each do |log|
      calls.concat(Playtypus::CallContainer.from_log(File.read(log)).calls)
    end
  else
    log_file = File.read(options[:call_log])
    calls = Playtypus::CallContainer.from_log(log_file).calls
  end
  unless options[:response_log].to_s.empty?
    FileUtils.mkdir_p options[:response_log]
  end
  gateway = Playtypus::Gateway.new(calls, sender, preserve_times, options[:response_log])
  gateway.playback()
end