class Rambo::CLI

Attributes

file[RW]
generator[RW]
options[RW]
stderr[RW]
stdout[RW]

Public Class Methods

new(raml_file=nil, opts={}, stdout=STDOUT, stderr=STDERR) click to toggle source
# File lib/cli.rb, line 6
def initialize(raml_file=nil, opts={}, stdout=STDOUT, stderr=STDERR)
  @stdout  = stdout
  @stderr  = stderr
  @file    = raml_file
  @options = opts

  validate!
end

Public Instance Methods

run!() click to toggle source
# File lib/cli.rb, line 15
def run!
  print_logo

  begin
    Rambo.generate_contract_tests!(file: file, options: options)

    stdout.puts("Generating contract tests...")
    sleep 0.4

    stdout.puts("Done!".green)
  rescue NoMethodError => e
    stderr.puts("Error: #{e.message}".red)
    stderr.puts "\t#{e.backtrace.join("\n\t")}"
  end
end
validate!() click to toggle source
# File lib/cli.rb, line 31
def validate!
  exit_for_missing_file unless file
  exit_for_invalid_file_format unless file.match(/\.raml$/)
end

Private Instance Methods

exit_for_invalid_file_format() click to toggle source
# File lib/cli.rb, line 50
def exit_for_invalid_file_format
  stdout.puts "Unsupported file format. Please choose a RAML file."
  exit 1
end
exit_for_missing_file() click to toggle source
# File lib/cli.rb, line 45
def exit_for_missing_file
  stdout.puts "USAGE: rambo [FILE]"
  exit 1
end