Class: Mutant::CLI Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Commandline parser / runner

rubocop:disable Metrics/ClassLength

Defined Under Namespace

Classes: OptionParser

Constant Summary collapse

OPTIONS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

%i[
  add_environment_options
  add_mutation_options
  add_filter_options
  add_debug_options
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.apply(world, config, arguments) ⇒ Either<OptionParser::ParseError, Config>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parse arguments into config

ignore :reek:LongParameterList

Parameters:

  • world (World)
  • config (Config)
  • arguments (Array<String>)

Returns:



59
60
61
62
63
# File 'lib/mutant/cli.rb', line 59

def self.apply(world, config, arguments)
  Either
    .wrap_error(OptionParser::ParseError) { new(world, config).parse(arguments) }
    .lmap(&:message)
end

.run(world, default_config, arguments) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Run cli with arguments

rubocop:disable Style/Semicolon

ignore :reek:LongParameterList

Parameters:

  • world (World)

    the outside world

  • default_config (Config)

    the default config

  • the (Array<String>)

    user provided arguments

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
46
47
# File 'lib/mutant/cli.rb', line 38

def self.run(world, default_config, arguments)
  License
    .apply(world)
    .bind { Config.load_config_file(world, default_config) }
    .bind { |file_config| apply(world, file_config, arguments) }
    .bind { |cli_config| Bootstrap.apply(world, cli_config) }
    .bind(&Runner.method(:apply))
    .from_right { |error| world.stderr.puts(error); return false }
    .success?
end

Instance Method Details

#parse(arguments) ⇒ Config

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parse the command-line options

Parameters:

  • arguments (Array<String>)

    Command-line options and arguments to be parsed.

Returns:



78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/mutant/cli.rb', line 78

def parse(arguments)
  opts = OptionParser.new do |builder|
    builder.banner = 'usage: mutant [options] MATCH_EXPRESSION ...'
    OPTIONS.each do |name|
      __send__(name, builder)
    end
  end

  parse_match_expressions(opts.parse!(arguments.dup))

  config
end