Class: Spex::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/spex/cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(args = []) ⇒ CLI

Returns a new instance of CLI.



7
8
9
# File 'lib/spex/cli.rb', line 7

def initialize(args = [])
  @args = args
end

Instance Method Details

#optionsObject



11
12
13
# File 'lib/spex/cli.rb', line 11

def options
  @options ||= OpenStruct.new
end

#parserObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/spex/cli.rb', line 15

def parser
  @parser ||= OptionParser.new do |opts|
    opts.banner = "spex [OPTIONS] DEFINITION_FILE"
    opts.separator "\nOPTIONS:"
    opts.on_tail('--help', '-h', 'Show this message') do
      puts opts
      exit
    end
    opts.on('--describe', '-d', 'Describe DEFINITION_FILE') do
      options.describe = true
    end
    opts.on('--checks', '-c', "List supported checks") do
      display_checks
      exit
    end
  end
end

#runObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/spex/cli.rb', line 33

def run
  parser.parse!(@args)
  filename = @args.shift
  if !filename
    refuse "No definition file given"
  elsif !File.exist?(filename)
    refuse "Definition file not found: #{filename}"
  else
    accept(filename)
  end
end