Class: PriorityTest::Core::OptionParser
- Inherits:
-
Object
- Object
- PriorityTest::Core::OptionParser
- Defined in:
- lib/priority_test/core/option_parser.rb
Constant Summary collapse
- AVAILABLE_TEST_FRAMEWORKS =
['rspec']
- OPTIONS =
['--priority']
Class Method Summary collapse
Instance Method Summary collapse
- #parse!(args) ⇒ Object
- #parse_options(args) ⇒ Object
- #parse_test_framework(args) ⇒ Object
- #parser(options) ⇒ Object
- #remove_parsed_options(args) ⇒ Object
Class Method Details
.parse!(args) ⇒ Object
9 10 11 |
# File 'lib/priority_test/core/option_parser.rb', line 9 def self.parse!(args) new.parse!(args) end |
Instance Method Details
#parse!(args) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/priority_test/core/option_parser.rb', line 32 def parse!(args) = (args) [:test_framework] = parse_test_framework(args) end |
#parse_options(args) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/priority_test/core/option_parser.rb', line 13 def (args) = {} opts_parser = parser() if args.empty? puts opts_parser return end begin opts_parser.parse!(args.clone) rescue ::OptionParser::InvalidOption end (args) end |
#parse_test_framework(args) ⇒ Object
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/priority_test/core/option_parser.rb', line 66 def parse_test_framework(args) test_framework = args.shift if AVAILABLE_TEST_FRAMEWORKS.include?(test_framework) test_framework else puts "Invalid test framework: #{test_framework}" puts "Run `pt -h` for more info" raise ::OptionParser::InvalidArgument end end |
#parser(options) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/priority_test/core/option_parser.rb', line 39 def parser() ::OptionParser.new do |parser| parser. = <<-EOS Usage: pt <test-framework> [options] [files or directories] Test framework: * rspec Options: EOS parser.on('--priority', 'Filter and run priority tests') do |o| [:priority] = true end parser.on_tail("-h", "--help", "Show help") do puts parser exit end parser.on_tail('-v', '--version', 'Show version') do puts PriorityTest::VERSION exit end end end |
#remove_parsed_options(args) ⇒ Object
77 78 79 |
# File 'lib/priority_test/core/option_parser.rb', line 77 def (args) args.reject! { |arg| OPTIONS.include?(arg) } end |