Class: Lookout::Interfaces::Commandline

Inherits:
Object
  • Object
show all
Defined in:
lib/lookout-3.0/interfaces/commandline.rb

Overview

Command-line interface to Lookout.

Instance Method Summary collapse

Constructor Details

#initialize(arguments = ARGV, pwd = Dir.pwd, io = $stderr) ⇒ Commandline

Processes ARGUMENTS, looking for options, running from the directory PWD and outputting results to IO.

Valid arguments are

  • –: Stops processing of options, treating remaining arguments as files

  • -rFEATURE: Requires FEATURE

  • -lLINE: Only runs expectation closest before or on LINE

  • -c: Reports test coverage

  • FILENAME: Loads expectations from FILENAME, relative to PWD

Parameters:

  • arguments (Array<String>) (defaults to: ARGV)
  • pwd (String) (defaults to: Dir.pwd)
  • io (IO) (defaults to: $stderr)

Raises:

  • (ArgumentError)

    If an unknown option exists among ARGUMENTS



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/lookout-3.0/interfaces/commandline.rb', line 20

def initialize(arguments = ARGV, pwd = Dir.pwd, io = $stderr)
  @pwd, @io = pwd, io
  @line = nil
  @files = []
  @requires = []
  @coverage = false
  only_load = false
  arguments.each do |argument|
    if not only_load and argument == '--'
      only_load = true
    elsif not only_load and argument =~ /\A-r(.*)/
      @requires << $1
    elsif not only_load and argument =~ /\A-l(.*)/
      @line = $1.to_i
    elsif not only_load and argument == '-c'
      @coverage = true
    elsif not only_load and argument =~ /\A-/
      raise ArgumentError, 'unknown option: %s' % argument
    else
      @files << [File.expand_path(argument, pwd), argument]
    end
  end
end

Instance Method Details

#callBoolean

Requires requested features, sets up coverage reporting, if desired, and checks the requested expectations. Coverage reporting will only be done if all expectations passed.

Returns:

  • (Boolean)

    True if all expectations passed



49
50
51
52
53
54
55
# File 'lib/lookout-3.0/interfaces/commandline.rb', line 49

def call
  require
  coverage do
    return false unless expectations
  end
  true
end