Class: SimpleCovMcp::CoverageCLI
- Inherits:
-
Object
- Object
- SimpleCovMcp::CoverageCLI
- Defined in:
- lib/simplecov_mcp/cli.rb
Constant Summary collapse
- SUBCOMMANDS =
%w[list summary raw uncovered detailed totals validate version].freeze
- HORIZONTAL_RULE =
'-' * 79
- OPTIONS_EXPECTING_ARGUMENT =
Reference shared constant to avoid duplication with ModeDetector
Constants::OPTIONS_EXPECTING_ARGUMENT
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize(error_handler: nil) ⇒ CoverageCLI
constructor
Initialize CLI for pure CLI usage only.
- #run(argv) ⇒ Object
- #show_default_report(sort_order: :descending, output: $stdout) ⇒ Object
Constructor Details
#initialize(error_handler: nil) ⇒ CoverageCLI
Initialize CLI for pure CLI usage only. Always runs as CLI, no mode detection needed.
24 25 26 27 28 29 30 |
# File 'lib/simplecov_mcp/cli.rb', line 24 def initialize(error_handler: nil) @config = AppConfig.new @cmd = nil @cmd_args = [] @custom_error_handler = error_handler # Store custom handler if provided @error_handler = nil # Will be created after parsing options end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
20 21 22 |
# File 'lib/simplecov_mcp/cli.rb', line 20 def config @config end |
Instance Method Details
#run(argv) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/simplecov_mcp/cli.rb', line 32 def run(argv) context = nil # argv should already include environment options (merged by caller) # Pre-scan for error-mode to ensure early errors are logged with correct verbosity pre_scan_error_mode(argv) (argv) enforce_version_subcommand_if_requested context = SimpleCovMcp.create_context( error_handler: error_handler, # construct after options to respect --error-mode log_target: config.log_file.nil? ? SimpleCovMcp.context.log_target : config.log_file, mode: :cli ) SimpleCovMcp.with_context(context) do if @cmd run_subcommand(@cmd, @cmd_args) else show_default_report(sort_order: config.sort_order) end end rescue OptionParser::ParseError => e # Handle any option parsing errors (invalid option/argument) without relying on # @error_handler, which is not guaranteed to be initialized yet. with_context_if_available(context) { handle_option_parser_error(e, argv: argv) } rescue SimpleCovMcp::Error => e with_context_if_available(context) { handle_user_facing_error(e) } end |
#show_default_report(sort_order: :descending, output: $stdout) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/simplecov_mcp/cli.rb', line 61 def show_default_report(sort_order: :descending, output: $stdout) model = CoverageModel.new(**config.) presenter = Presenters::ProjectCoveragePresenter.new( model: model, sort_order: sort_order, check_stale: (config.staleness == :error), tracked_globs: config.tracked_globs ) if config.format != :table require_relative 'formatters' output.puts Formatters.format(presenter.relativized_payload, config.format) return end file_summaries = presenter.relative_files output.puts model.format_table( file_summaries, sort_order: sort_order, check_stale: (config.staleness == :error), tracked_globs: nil ) end |