Module: TestBoosters::CliParser

Defined in:
lib/test_boosters/cli_parser.rb

Class Method Summary collapse

Class Method Details

.parseObject

:reek:TooManyStatements :reek:NestedIterators :reek:DuplicateMethodCall



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/test_boosters/cli_parser.rb', line 8

def parse
  options = {}

  parser = OptionParser.new do |opts|
    opts.on(
      "--thread INDEX",
      "[DEPRECATED] Use the '--job' option instead"
    ) do |parameter|
      puts "[DEPRECATION WARNING] The '--thread' parameter is deprecated. Please use '--job' instead."

      options.merge!(parse_job_params(parameter))
    end

    opts.on(
      "--job INDEX",
      "The job index and number of total jobs. e.g. --job 4/32"
    ) do |parameter|
      options.merge!(parse_job_params(parameter))
    end

    opts.on(
      "--dry-run",
      "Only print the files that will be run for this job index"
    ) do |parameter|
      options.merge!(:dry_run => parameter)
    end
  end

  parser.parse!

  options
end

.parse_job_params(input_parameter) ⇒ Object

parses input like ‘1/32’ and outputs { :job_index => 1, :job_count => 32 }



42
43
44
45
46
# File 'lib/test_boosters/cli_parser.rb', line 42

def parse_job_params(input_parameter)
  job_index, job_count, _rest = input_parameter.split("/")

  { :job_index => job_index.to_i, :job_count => job_count.to_i }
end