Class: Gurke::CLI
- Inherits:
-
Object
- Object
- Gurke::CLI
- Defined in:
- lib/gurke/cli.rb
Instance Method Summary collapse
- #call(options, files) ⇒ Object
-
#parser ⇒ Object
rubocop:disable MethodLength.
- #print_help ⇒ Object
- #print_version ⇒ Object
-
#run(argv) ⇒ Object
Run CLI with given arguments.
Instance Method Details
#call(options, files) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/gurke/cli.rb', line 22 def call(, files) if File.exist?(Gurke.root.join('gurke.rb')) require File.(Gurke.root.join('gurke.rb')) end [:require].each do |r| Dir[r].each{|f| require File.(f) } end if [:require].any? files = Dir[[:pattern].to_s] if files.empty? && [:pattern] files.map!{|f| File.(f) } runner = if [:drb_server] Runner::DRbServer elsif [:drb] Runner::DRbClient else Runner::LocalRunner end.new Gurke.config, Kernel.exit runner.run files end |
#parser ⇒ Object
rubocop:disable MethodLength
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/gurke/cli.rb', line 56 def parser @parser ||= Trollop::Parser.new do opt :help, 'Print this help.' opt :version, 'Show program version information.' opt :backtrace, 'Show full error backtraces.' 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 |
#print_help ⇒ Object
51 52 53 |
# File 'lib/gurke/cli.rb', line 51 def print_help parser.educate($stdout) end |
#print_version ⇒ Object
45 46 47 48 49 |
# File 'lib/gurke/cli.rb', line 45 def print_version $stdout.puts <<-EOF.gsub(/^ {8}/, '') gurke v#{Gurke::VERSION} EOF end |
#run(argv) ⇒ Object
Run CLI with given arguments.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/gurke/cli.rb', line 10 def run(argv) call parser.parse(argv), argv rescue Trollop::VersionNeeded print_version && exit rescue Trollop::HelpNeeded print_help && exit rescue Trollop::CommandlineError => e $stderr.puts "Error: #{e}" $stderr.puts "Run with `-h' for more information on available arguments." exit 255 end |