Class: Inquirex::TTY::Commands::Run

Inherits:
Dry::CLI::Command
  • Object
show all
Defined in:
lib/inquirex/tty/commands/run.rb

Overview

Runs a flow definition interactively via TTY prompts and writes the collected answers (plus metadata) as JSON to stderr or a file.

Instance Method Summary collapse

Instance Method Details

#call(flow_file:, **options) ⇒ void

This method returns an undefined value.

Parameters:

  • flow_file (String)
  • options (Hash)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/inquirex/tty/commands/run.rb', line 17

def call(flow_file:, **options)
  engine = run_flow(flow_file)
  json   = JSON.pretty_generate(build_result(flow_file, engine))

  if options[:output]
    File.write(options[:output], json)
    puts "\nResults saved to #{options[:output]}"
  else
    $stderr.puts json # rubocop:disable Style/StderrPuts
  end
rescue Inquirex::TTY::Error => e
  error(e.message)
  exit 1
rescue Inquirex::Errors::Error => e
  error("Engine error: #{e.message}")
  exit 1
end