Class: SimpleCovMcp::Commands::ValidateCommand
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- SimpleCovMcp::Commands::ValidateCommand
- Defined in:
- lib/simplecov_mcp/commands/validate_command.rb
Overview
Validates coverage data against a predicate. Exits with code 0 (pass), 1 (fail), or 2 (error).
Usage:
simplecov-mcp validate policy.rb # File mode
simplecov-mcp validate -i '->(m) { ... }' # Inline mode
Instance Attribute Summary
Attributes inherited from BaseCommand
#cli, #config, #source_formatter
Instance Method Summary collapse
Methods inherited from BaseCommand
Constructor Details
This class inherits a constructor from SimpleCovMcp::Commands::BaseCommand
Instance Method Details
#execute(args) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 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 |
# File 'lib/simplecov_mcp/commands/validate_command.rb', line 15 def execute(args) # Parse command-specific options inline_mode = false code = nil # Simple option parsing for -i/--inline flag while args.first&.start_with?('-') case args.first when '-i', '--inline' inline_mode = true args.shift code = args.shift or raise UsageError.for_subcommand('validate -i <code>') else raise UsageError, "Unknown option for validate: #{args.first}" end end # If not inline mode, expect a file path as positional argument unless inline_mode file_path = args.shift or raise UsageError.for_subcommand('validate <file> | -i <code>') code = file_path end # Evaluate the predicate result = if inline_mode PredicateEvaluator.evaluate_code(code, model) else PredicateEvaluator.evaluate_file(code, model) end exit(result ? 0 : 1) rescue UsageError # Usage errors should exit with code 1, not 2 raise rescue => e handle_predicate_error(e) end |