Class: Gurke::CLI

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

Instance Method Summary collapse

Instance Method Details

#call(options, files) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/gurke/cli.rb', line 24

def call(options, files)
  if File.exist?(Gurke.root.join('gurke.rb'))
    require File.expand_path(Gurke.root.join('gurke.rb'))
  end

  if options[:require].any?
    options[:require].each do |r|
      Dir[r].each {|f| require File.expand_path(f) }
    end
  end

  files = expand_files files, options

  runner = if options[:drb_server]
             Runner::DRbServer
           elsif options[:drb]
             Runner::DRbClient
           else
             Runner::LocalRunner
           end.new(Gurke.config, options)

  Kernel.exit runner.run files
end

#parserObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/gurke/cli.rb', line 58

def parser
  @parser ||= Optimist::Parser.new do
    opt :help, 'Print this help.'
    opt :version, 'Show program version information.'
    opt :backtrace, 'Show full error backtraces.'
    opt :formatter, 'Select a special formatter as reporter', \
      default: 'default'
    opt :pattern, 'File pattern matching feature files to be run.',
      default: 'features/**/*.feature'
    opt :require, 'Files matching this pattern will be required after' \
                  'loading environment but before running features.',
      default: ['features/steps/**/*.rb',
                'features/support/steps/**/*.rb',],
      multi: true
    opt :tags, 'Only run features and scenarios matching given tag ' \
               'filtering expression. TODO: Description.',
      default: ['~wip'],
      multi: true
    opt :drb_server, 'Run gurke DRb server. (experimental)', short: :none
    opt :drb, 'Run features on already started DRb server. (experimental)',
      short: :none
  end
end


54
55
56
# File 'lib/gurke/cli.rb', line 54

def print_help
  parser.educate($stdout)
end


48
49
50
51
52
# File 'lib/gurke/cli.rb', line 48

def print_version
  $stdout.puts <<~VSTR
    gurke v#{Gurke::VERSION}
  VSTR
end

#run(argv) ⇒ Object

Run CLI with given arguments.

Parameters:

  • argv (Array<String>)

    Tokenized argument list.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/gurke/cli.rb', line 12

def run(argv)
  call parser.parse(argv), argv
rescue Optimist::VersionNeeded
  print_version && exit
rescue Optimist::HelpNeeded
  print_help && exit
rescue Optimist::CommandlineError => e
  warn "Error: #{e}"
  warn "Run with `-h' for more information on available arguments."
  exit 255
end