Class: CovLoupe::Commands::CommandFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/cov_loupe/commands/command_factory.rb

Overview

Factory that maps subcommand names to their command classes. Validates the command name and raises UsageError with the full usage synopsis if the command is unknown.

Constant Summary collapse

COMMAND_MAP =
{
  'list'      => ListCommand,
  'summary'   => SummaryCommand,
  'raw'       => RawCommand,
  'uncovered' => UncoveredCommand,
  'detailed'  => DetailedCommand,
  'totals'    => TotalsCommand,
  'validate'  => ValidateCommand,
}.freeze

Class Method Summary collapse

Class Method Details

.available_commandsObject



40
41
42
# File 'lib/cov_loupe/commands/command_factory.rb', line 40

def self.available_commands
  COMMAND_MAP.keys
end

.create(command_name, cli_context) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cov_loupe/commands/command_factory.rb', line 28

def self.create(command_name, cli_context)
  command_class = COMMAND_MAP[command_name]
  unless command_class
    raise UsageError.for_subcommand(
      'list | summary <path> | raw <path> | uncovered <path> | detailed <path> ' \
        '| totals | validate <file> | validate -i <code>'
    )
  end

  command_class.new(cli_context)
end