Class: CovLoupe::OptionParsers::EnvOptionsParser
- Inherits:
-
Object
- Object
- CovLoupe::OptionParsers::EnvOptionsParser
- Defined in:
- lib/cov_loupe/option_parsers/env_options_parser.rb
Constant Summary collapse
- ENV_VAR =
'COV_LOUPE_OPTS'
Instance Method Summary collapse
-
#initialize(env_var: ENV_VAR) ⇒ EnvOptionsParser
constructor
A new instance of EnvOptionsParser.
- #parse_env_opts ⇒ Object
- #pre_scan_error_mode(argv, error_mode_normalizer: method(:normalize_error_mode)) ⇒ Object
Constructor Details
#initialize(env_var: ENV_VAR) ⇒ EnvOptionsParser
Returns a new instance of EnvOptionsParser.
11 12 13 |
# File 'lib/cov_loupe/option_parsers/env_options_parser.rb', line 11 def initialize(env_var: ENV_VAR) @env_var = env_var end |
Instance Method Details
#parse_env_opts ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/cov_loupe/option_parsers/env_options_parser.rb', line 15 def parse_env_opts opts_string = ENV[@env_var] return [] unless opts_string && !opts_string.empty? begin Shellwords.split(opts_string) rescue ArgumentError => e raise CovLoupe::ConfigurationError, "Invalid #{@env_var} format: #{e.}" end end |
#pre_scan_error_mode(argv, error_mode_normalizer: method(:normalize_error_mode)) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/cov_loupe/option_parsers/env_options_parser.rb', line 26 def pre_scan_error_mode(argv, error_mode_normalizer: method(:normalize_error_mode)) # Quick scan for --error-mode or -e to ensure early errors are logged correctly. # Scan in reverse so that the last occurrence (CLI) overrides earlier ones (ENV). i = argv.length - 1 while i >= 0 arg = argv[i] if %w[--error-mode -e].include?(arg) && argv[i + 1] return error_mode_normalizer.call(argv[i + 1]) elsif arg.start_with?('--error-mode=') value = arg.split('=', 2)[1] return error_mode_normalizer.call(value) elsif arg.start_with?('-e') && arg.length > 2 # Handle attached short option: -edebug value = arg[2..] return error_mode_normalizer.call(value) end i -= 1 end nil rescue # Ignore errors during pre-scan; they'll be caught during actual parsing nil end |