Class: CovLoupe::ConfigParser

Inherits:
Object
  • Object
show all
Defined in:
lib/cov_loupe/config/config_parser.rb

Overview

Parses command-line arguments into an AppConfig.

Used in both CLI and MCP modes to extract mode, log file, and other global settings before dispatching to the appropriate runner. Uses order! so that subcommand-specific options (e.g., 'validate -i') are not consumed by the global parser.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ ConfigParser

Returns a new instance of ConfigParser.



16
17
18
19
# File 'lib/cov_loupe/config/config_parser.rb', line 16

def initialize(argv)
  @argv = argv
  @config = AppConfig.new
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



14
15
16
# File 'lib/cov_loupe/config/config_parser.rb', line 14

def argv
  @argv
end

#configObject (readonly)

Returns the value of attribute config.



14
15
16
# File 'lib/cov_loupe/config/config_parser.rb', line 14

def config
  @config
end

Class Method Details

.parse(argv) ⇒ AppConfig

Parse argv (with env opts already merged) and return config

Parameters:

  • argv (Array<String>)

    command-line arguments (should include env opts if needed)

Returns:

  • (AppConfig)

    populated configuration object



24
25
26
# File 'lib/cov_loupe/config/config_parser.rb', line 24

def self.parse(argv)
  new(argv).parse
end

Instance Method Details

#parseObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cov_loupe/config/config_parser.rb', line 28

def parse
  # Build and execute the option parser
  parser = OptionParserBuilder.new(config).build_option_parser

  # Use order! to stop at the first non-option argument (the subcommand).
  # This ensures that subcommand-specific options (like 'validate -i') are not
  # stripped by the global option parser.
  parser.order!(argv)

  config.validate!
end