Class: Specwrk::CLI::Seed

Inherits:
Dry::CLI::Command
  • Object
show all
Includes:
Clientable
Defined in:
lib/specwrk/cli.rb

Instance Method Summary collapse

Methods included from Hookable

extended, #included, #included_hooks, #on_included, #on_setup, #setup_hooks

Instance Method Details

#call(max_retries:, dir:, **args) ⇒ Object



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/specwrk/cli.rb', line 172

def call(max_retries:, dir:, **args)
  dir = ["spec"] if dir.length.zero?

  self.class.setup(**args)

  require "specwrk/list_examples"
  require "specwrk/client"

  ENV["SPECWRK_SEED"] = "1"
  examples = ListExamples.new(dir).examples

  Client.wait_for_server!
  Client.new.seed(examples, max_retries)
  file_count = examples.group_by { |e| e[:file_path] }.keys.size
  puts "🌱 Seeded #{examples.size} examples across #{file_count} files"
rescue Errno::ECONNREFUSED
  puts "Server at #{ENV.fetch("SPECWRK_SRV_URI", "http://localhost:5138")} is refusing connections, exiting...#{ENV["SPECWRK_FLUSH_DELIMINATOR"]}"
  exit 1
rescue Errno::ECONNRESET
  puts "Server at #{ENV.fetch("SPECWRK_SRV_URI", "http://localhost:5138")} stopped responding to connections, exiting...#{ENV["SPECWRK_FLUSH_DELIMINATOR"]}"
  exit 1
end