Class: Henitai::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/henitai/cli.rb

Overview

Command-line interface entry point.

Usage:

henitai run [options] [SUBJECT_PATTERN...]

Options:

--since GIT_REF   Only mutate subjects changed since GIT_REF
--use INTEGRATION Override integration from config (e.g. rspec)
--config PATH     Path to .henitai.yml (default: .henitai.yml)
--operators SET   Operator set: light (default) | full
--jobs N          Number of parallel workers (default: 1)
--all-logs        Print all captured child logs
-h, --help        Show this help message
-v, --version     Show version

rubocop:disable Metrics/ClassLength

Constant Summary collapse

INIT_TEMPLATE_LINES =
[
  "# yaml-language-server: $schema=./assets/schema/henitai.schema.json",
  "includes:",
  "  - lib",
  "mutation:",
  "  operators: light",
  "  timeout: 10.0",
  "  max_flaky_retries: 3",
  "  sampling:",
  "    ratio: 0.05",
  "    strategy: stratified",
  "reports_dir: reports",
  "thresholds:",
  "  high: 80",
  "  low: 60"
].freeze
OPERATOR_METADATA =
{
  "ArithmeticOperator" => ["Arithmetic operators", "a + b -> a - b"],
  "EqualityOperator" => ["Comparison operators", "a == b -> a != b"],
  "LogicalOperator" => ["Boolean operators", "a && b -> a || b"],
  "BooleanLiteral" => ["Boolean literals", "true -> false"],
  "ConditionalExpression" => ["Conditional branches", "if cond then ... end"],
  "StringLiteral" => ["String literals", '"foo" -> ""'],
  "ReturnValue" => ["Return expressions", "return x -> return nil"],
  "ArrayDeclaration" => ["Array literals", "[1, 2] -> []"],
  "HashLiteral" => ["Hash literals", "{ a: 1 } -> {}"],
  "RangeLiteral" => ["Range literals", "1..5 -> 1...5"],
  "SafeNavigation" => ["Safe navigation", "user&.name -> user.name"],
  "PatternMatch" => ["Pattern matching", "in { x: Integer } -> in { x: String }"],
  "BlockStatement" => ["Block statements", "{ do_work } -> {}"],
  "MethodExpression" => ["Method calls", "call_service -> nil"],
  "AssignmentExpression" => ["Assignment expressions", "x += 1 -> x -= 1"],
  "MethodChainUnwrap" => ["Method chain unwrap", "a.b.c -> a.b"],
  "RegexMutator" => ["Regex literals", "/foo+/ -> /foo*/"],
  "UnaryOperator" => ["Unary operators", "-x -> x"],
  "UpdateOperator" => ["Compound assignment", "x += 1 -> x -= 1"]
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



64
65
66
# File 'lib/henitai/cli.rb', line 64

def initialize(argv)
  @argv = argv.dup
end

Class Method Details

.start(argv) ⇒ Object



60
61
62
# File 'lib/henitai/cli.rb', line 60

def self.start(argv)
  new(argv).run
end

Instance Method Details

#runObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/henitai/cli.rb', line 68

def run
  command = @argv.shift
  case command
  when "run"     then run_command
  when "version" then puts Henitai::VERSION
  when "init"    then init_command
  when "operator" then operator_command
  when nil, "-h", "--help" then puts help_text
  else
    warn "Unknown command: #{command}"
    warn help_text
    exit 1
  end
end