Sha256: ba57f5125e55172cb0d6e8101239e17f3541e3e72d914ddf3220663c26d3ca59

Contents?: true

Size: 1.92 KB

Versions: 2

Compression:

Stored size: 1.92 KB

Contents

require 'trollop'

module Gurke
  #
  class CLI
    #
    # Run CLI with given arguments.
    #
    # @param argv [Array<String>] Tokenized argument list.
    #
    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

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

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

      files  = Dir[options[:pattern].to_s] if files.empty? && options[:pattern]
      status = Runner.new(Gurke.config, files, options).run

      Kernel.exit(status)
    end

    def print_version
      $stdout.puts <<-EOF.gsub(/^ {8}/, '')
        gurke v#{Gurke::VERSION}
      EOF
    end

    def print_help
      parser.educate($stdout)
    end

    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
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gurke-2.0.0.dev.1.b20 lib/gurke/cli.rb
gurke-2.0.0.dev.1.b19 lib/gurke/cli.rb