Class: SimpleCovMcp::OptionParsers::ErrorHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/simplecov_mcp/option_parsers/error_helper.rb

Constant Summary collapse

SUBCOMMANDS =
%w[list summary raw uncovered detailed totals version].freeze

Instance Method Summary collapse

Constructor Details

#initialize(subcommands = SUBCOMMANDS) ⇒ ErrorHelper

Returns a new instance of ErrorHelper.



8
9
10
# File 'lib/simplecov_mcp/option_parsers/error_helper.rb', line 8

def initialize(subcommands = SUBCOMMANDS)
  @subcommands = subcommands
end

Instance Method Details

#handle_option_parser_error(error, argv: [], usage_hint: "Run '#{program_name} --help' for usage information.") ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/simplecov_mcp/option_parsers/error_helper.rb', line 12

def handle_option_parser_error(error, argv: [], usage_hint: "Run '#{program_name} --help' for usage information.")
  message = error.message.to_s
  # Suggest a subcommand when an invalid option matches a known subcommand
  option = extract_invalid_option(message)

  if option&.start_with?('--') && @subcommands.include?(option[2..])
    suggest_subcommand(option)
  else
    # Generic message from OptionParser
    warn "Error: #{message}"
    # Attempt to derive a helpful hint for enumerated options
    if (hint = build_enum_value_hint(argv))
      warn hint
    end
  end
  warn usage_hint
  exit 1
end