Module: SimpleCovMcp::OptionNormalizers

Defined in:
lib/simplecov_mcp/option_normalizers.rb

Overview

Shared normalization logic for CLI options. Provides both strict (raise on invalid) and lenient (default on invalid) modes.

Constant Summary collapse

SORT_ORDER_MAP =
{
  'a' => :ascending,
  'ascending' => :ascending,
  'd' => :descending,
  'descending' => :descending
}.freeze
SOURCE_MODE_MAP =
{
  'f' => :full,
  'full' => :full,
  'u' => :uncovered,
  'uncovered' => :uncovered
}.freeze
STALENESS_MAP =
{
  'o' => :off,
  'off' => :off,
  'e' => :error,
  'error' => :error
}.freeze
ERROR_MODE_MAP =
{
  'off' => :off,
  'o' => :off,
  'log' => :log,
  'l' => :log,
  'debug' => :debug,
  'd' => :debug
}.freeze
FORMAT_MAP =
{
  't' => :table,
  'table' => :table,
  'j' => :json,
  'json' => :json,
  'J' => :pretty_json,
  'pretty_json' => :pretty_json,
  'pretty-json' => :pretty_json,
  'y' => :yaml,
  'yaml' => :yaml,
  'a' => :awesome_print,
  'awesome_print' => :awesome_print,
  'ap' => :awesome_print
}.freeze

Class Method Summary collapse

Class Method Details

.normalize_error_mode(value, strict: true, default: :log) ⇒ Symbol

Normalize error mode value.

Parameters:

  • value (String, Symbol, nil)

    The value to normalize

  • strict (Boolean) (defaults to: true)

    If true, raises on invalid value; if false, returns default

  • default (Symbol) (defaults to: :log)

    The default value to return if invalid and not strict

Returns:

  • (Symbol)

    The normalized symbol or default if invalid and not strict

Raises:

  • (OptionParser::InvalidArgument)

    If strict and value is invalid

  • (OptionParser::InvalidArgument)


92
93
94
95
96
97
98
# File 'lib/simplecov_mcp/option_normalizers.rb', line 92

module_function def normalize_error_mode(value, strict: true, default: :log)
  normalized = ERROR_MODE_MAP[value.to_s.downcase]
  return normalized if normalized
  raise OptionParser::InvalidArgument, "invalid argument: #{value}" if strict

  default
end

.normalize_format(value, strict: true) ⇒ Symbol?

Normalize format value.

Parameters:

  • value (String, Symbol)

    The value to normalize

  • strict (Boolean) (defaults to: true)

    If true, raises on invalid value; if false, returns nil

Returns:

  • (Symbol, nil)

    The normalized symbol or nil if invalid and not strict

Raises:

  • (OptionParser::InvalidArgument)

    If strict and value is invalid

  • (OptionParser::InvalidArgument)


105
106
107
108
109
110
111
# File 'lib/simplecov_mcp/option_normalizers.rb', line 105

module_function def normalize_format(value, strict: true)
  normalized = FORMAT_MAP[value.to_s.downcase]
  return normalized if normalized
  raise OptionParser::InvalidArgument, "invalid argument: #{value}" if strict

  nil
end

.normalize_sort_order(value, strict: true) ⇒ Object

Raises:

  • (OptionParser::InvalidArgument)


52
53
54
55
56
57
58
# File 'lib/simplecov_mcp/option_normalizers.rb', line 52

module_function def normalize_sort_order(value, strict: true)
  normalized = SORT_ORDER_MAP[value.to_s.downcase]
  return normalized if normalized
  raise OptionParser::InvalidArgument, "invalid argument: #{value}" if strict

  nil
end

.normalize_source_mode(value, strict: true) ⇒ Symbol?

Normalize source mode value.

Parameters:

  • value (String, Symbol, nil)

    The value to normalize

  • strict (Boolean) (defaults to: true)

    If true, raises on invalid value; if false, returns nil

Returns:

  • (Symbol, nil)

    The normalized symbol or nil if invalid and not strict

Raises:

  • (OptionParser::InvalidArgument)

    If strict and value is invalid

  • (OptionParser::InvalidArgument)


65
66
67
68
69
70
71
# File 'lib/simplecov_mcp/option_normalizers.rb', line 65

module_function def normalize_source_mode(value, strict: true)
  normalized = SOURCE_MODE_MAP[value.to_s.downcase]
  return normalized if normalized
  raise OptionParser::InvalidArgument, "invalid argument: #{value}" if strict

  nil
end

.normalize_staleness(value, strict: true) ⇒ Symbol?

Normalize stale mode value.

Parameters:

  • value (String, Symbol)

    The value to normalize

  • strict (Boolean) (defaults to: true)

    If true, raises on invalid value; if false, returns nil

Returns:

  • (Symbol, nil)

    The normalized symbol or nil if invalid and not strict

Raises:

  • (OptionParser::InvalidArgument)

    If strict and value is invalid

  • (OptionParser::InvalidArgument)


78
79
80
81
82
83
84
# File 'lib/simplecov_mcp/option_normalizers.rb', line 78

module_function def normalize_staleness(value, strict: true)
  normalized = STALENESS_MAP[value.to_s.downcase]
  return normalized if normalized
  raise OptionParser::InvalidArgument, "invalid argument: #{value}" if strict

  nil
end