module RainforestCli

frozen_string_literal: true

Constants

THREADS
VERSION

Public Class Methods

http_client() click to toggle source
# File lib/rainforest_cli.rb, line 68
def self.http_client
  @http_client
end
logger() click to toggle source
# File lib/rainforest_cli.rb, line 60
def self.logger
  @logger ||= Logger.new(STDOUT)
end
logger=(logger) click to toggle source
# File lib/rainforest_cli.rb, line 64
def self.logger=(logger)
  @logger = logger
end
start(args) click to toggle source
# File lib/rainforest_cli.rb, line 25
def self.start(args)
  options = OptionParser.new(args)
  commands = Commands.new do |c|
    c.add('run', 'Run your tests on Rainforest') { Runner.new(options).run }
    c.add('new', 'Create a new RFML test') { TestFiles.new(options).create_file }
    c.add('validate', 'Validate your RFML tests') { Validator.new(options).validate }
    c.add('upload', 'Upload your RFML tests') { Uploader.new(options).upload }
    c.add('rm', 'Remove an RFML test locally and remotely') { Deleter.new(options).delete }
    c.add('export', 'Export your remote Rainforest tests to RFML') { Exporter.new(options).export }
    c.add('csv-upload', 'Upload a new tabular variable from a CSV file') { CSVImporter.new(options).import }
    c.add('report', 'Create a JUnit report from your run results') { Reporter.new(options).report }
    c.add('sites', 'Lists the available sites') { Resources.new(options).sites }
    c.add('folders', 'Lists the available folders') { Resources.new(options).folders }
    c.add('browsers', 'Lists the available browsers') { Resources.new(options).browsers }
  end

  @http_client = HttpClient.new(token: options.token)
  ::Rainforest.api_key = options.token

  if args.size == 0
    commands.print_documentation
    options.print_documentation
  end

  begin
    options.validate!
  rescue OptionParser::ValidationError => e
    logger.fatal e.message
    exit 2
  end

  commands.call(options.command) if options.command
  true
end