lib/mutant/cli.rb in mutant-0.8.0 vs lib/mutant/cli.rb in mutant-0.8.1

- old
+ new

@@ -16,11 +16,10 @@ # # @return [Fixnum] # the exit status # # @api private - # def self.run(arguments) Runner.call(Env::Bootstrap.call(call(arguments))).success? ? EXIT_SUCCESS : EXIT_FAILURE rescue Error => exception $stderr.puts(exception.message) EXIT_FAILURE @@ -31,23 +30,21 @@ # @param [Array<String>] # # @return [undefined] # # @api private - # def initialize(arguments) @config = Config::DEFAULT parse(arguments) end - # Return config + # Config parsed from CLI # # @return [Config] # # @api private - # attr_reader :config private # Parse the command-line options @@ -59,11 +56,10 @@ # An error occurred while parsing the options. # # @return [undefined] # # @api private - # def parse(arguments) opts = OptionParser.new do |builder| builder.banner = 'usage: mutant [options] MATCH_EXPRESSION ...' %w[add_environment_options add_mutation_options add_filter_options add_debug_options].each do |name| __send__(name, builder) @@ -80,29 +76,27 @@ # @param [Array<String>] expressions # # @return [undefined] # # @api private - # def parse_match_expressions(expressions) fail Error, 'No expressions given' if expressions.empty? - expressions.map(&Expression.method(:parse)).each do |expression| - add_matcher(:match_expressions, expression) + expressions.each do |expression| + add_matcher(:match_expressions, config.expression_parser.(expression)) end end # Add environmental options # # @param [Object] opts # # @return [undefined] # - # @api private - # # rubocop:disable MethodLength # + # @api private def add_environment_options(opts) opts.separator('Environment:') opts.on('--zombie', 'Run mutant zombified') do update(zombie: true) end @@ -122,11 +116,10 @@ # @param [String] name # # @return [undefined] # # @api private - # def setup_integration(name) update(integration: Integration.setup(name)) rescue LoadError raise Error, "Could not load integration #{name.inspect} (you may want to try installing the gem mutant-#{name})" end @@ -136,11 +129,10 @@ # @param [OptionParser] opts # # @return [undefined] # # @api private - # def add_mutation_options(opts) opts.separator(nil) opts.separator('Options:') opts.on( @@ -157,25 +149,26 @@ # @param [OptionParser] opts # # @return [undefined] # # @api private - # def add_filter_options(opts) - opts.on('--ignore-subject PATTERN', 'Ignore subjects that match PATTERN') do |pattern| - add_matcher(:subject_ignores, Expression.parse(pattern)) + opts.on('--ignore-subject EXPRESSION', 'Ignore subjects that match EXPRESSION as prefix') do |pattern| + add_matcher(:ignore_expressions, config.expression_parser.(pattern)) end + opts.on('--since REVISION', 'Only select subjects touched since REVISION') do |revision| + add_matcher(:subject_filters, Repository::SubjectFilter.new(Repository::Diff.from_head(revision))) + end end # Add debug options # # @param [OptionParser] opts # # @return [undefined] # # @api private - # def add_debug_options(opts) opts.on('--fail-fast', 'Fail fast') do update(fail_fast: true) end opts.on('--version', 'Print mutants version') do @@ -196,11 +189,10 @@ # @param [Hash<Symbol, Object>] attributes # # @return [undefined] # # @api private - # def update(attributes) @config = @config.update(attributes) end # Add configuration @@ -212,11 +204,10 @@ # the value to add # # @return [undefined] # # @api private - # def add(attribute, value) update(attribute => config.public_send(attribute).dup << value) end # Add matcher configuration @@ -228,10 +219,9 @@ # the value to add # # @return [undefined] # # @api private - # def add_matcher(attribute, value) update(matcher: config.matcher.add(attribute, value)) end end # CLI