Module: Dry::CLI::Parser

Defined in:
lib/allure_report_publisher/lib/parser.rb

Overview

Parser overload to support loading all options from environment variables

Defined Under Namespace

Classes: InvalidEnvValue

Constant Summary collapse

ENV_VAR_PREFIX =
"ALLURE_".freeze

Class Method Summary collapse

Class Method Details

.call(command, arguments, prog_name) ⇒ Object



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
# File 'lib/allure_report_publisher/lib/parser.rb', line 11

def call(command, arguments, prog_name)
  original_arguments = arguments.dup
  parsed_options = {}

  OptionParser.new do |opts|
    command.options.each do |option|
      opts.on(*option.parser_options) do |value|
        parsed_options[option.name.to_sym] = value
      end
    end

    opts.on_tail("-h", "--help") do
      return Result.help
    end
  end.parse!(arguments)

  parsed_options = command
                   .default_params
                   .merge(load_options(command.options, parsed_options))

  parse_required_params(command, arguments, prog_name, parsed_options)
rescue ::OptionParser::ParseError, InvalidEnvValue => e
  return Result.failure(e.message) if e.is_a?(InvalidEnvValue)

  Result.failure("ERROR: \"#{prog_name}\" was called with arguments \"#{original_arguments.join(' ')}\"")
end