Sha256: 393af66cc7c65e7b9aedb5e8b431f8c98ec90f0b59d9b994a64b169fa64ada28

Contents?: true

Size: 1.23 KB

Versions: 9

Compression:

Stored size: 1.23 KB

Contents

require "colorize"
require "rambo"

module Rambo
  class CLI
    def initialize(raml_file=nil, opts={}, stdout=STDOUT, stderr=STDERR)
      @stdout  = stdout
      @stderr  = stderr
      @file    = raml_file
      @options = opts

      validate!
    end

    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

    def validate!
      exit_for_missing_file unless file
      exit_for_invalid_file_format unless file.match(/\.raml$/)
    end

    private

    attr_accessor :file, :stdout, :stderr, :generator, :options

    def print_logo
      stdout.puts logo.colorize(color: String.colors.sample)
      sleep 0.4
    end

    def exit_for_missing_file
      stdout.puts "USAGE: rambo [FILE]"
      exit 1
    end

    def exit_for_invalid_file_format
      stdout.puts "Unsupported file format. Please choose a RAML file."
      exit 1
    end

    def logo
      File.read(File.expand_path("../../assets/logo.txt", __FILE__))
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rambo_ruby-0.7.1 lib/cli.rb
rambo_ruby-0.7.0 lib/cli.rb
rambo_ruby-0.6.0 lib/cli.rb
rambo_ruby-0.5.0 lib/cli.rb
rambo_ruby-0.4.0 lib/cli.rb
rambo_ruby-0.3.3 lib/cli.rb
rambo_ruby-0.3.2 lib/cli.rb
rambo_ruby-0.3.1 lib/cli.rb
rambo_ruby-0.3.0 lib/cli.rb