Sha256: 7b1f60137f5a2559b62cbe13fa6f38ab045097c63a562595ad691cf8636a437e

Contents?: true

Size: 1.22 KB

Versions: 6

Compression:

Stored size: 1.22 KB

Contents

module TestBoosters
  module CliParser
    module_function

    # :reek:TooManyStatements
    # :reek:NestedIterators
    # :reek:DuplicateMethodCall
    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

    # parses input like '1/32' and outputs { :job_index => 1, :job_count => 32 }
    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

  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
semaphore_test_boosters-2.7.1 lib/test_boosters/cli_parser.rb
semaphore_test_boosters-2.7.0 lib/test_boosters/cli_parser.rb
treye-semaphore_test_boosters-2.5.2 lib/test_boosters/cli_parser.rb
semaphore_test_boosters-2.6.0 lib/test_boosters/cli_parser.rb
treye-semaphore_test_boosters-2.5.1 lib/test_boosters/cli_parser.rb
semaphore_test_boosters-2.5.0 lib/test_boosters/cli_parser.rb