lib/undercover/options.rb in undercover-0.5.0 vs lib/undercover/options.rb in undercover-0.6.0
- old
+ new
@@ -2,11 +2,11 @@
require 'optparse'
require 'pathname'
module Undercover
- class Options
+ class Options # rubocop:disable Metrics/ClassLength
RUN_MODE = [
RUN_MODE_DIFF_STRICT = :diff_strict, # warn for changed lines
# RUN_MODE_DIFF_FILES = :diff_files, # warn for changed whole files
# RUN_MODE_ALL = :diff_all, # warn for allthethings
# RUN_MODE_FILES = :files # warn for specific files (cli option)
@@ -15,20 +15,30 @@
OUTPUT_FORMATTERS = [
OUTPUT_STDOUT = :stdout, # outputs warnings to stdout with exit 1
# OUTPUT_CIRCLEMATOR = :circlemator # posts warnings as review comments
].freeze
- attr_accessor :lcov, :path, :git_dir, :compare, :syntax_version
+ DEFAULT_FILE_INCLUDE_GLOBS = %w[*.rb *.rake *.ru Rakefile].freeze
+ attr_accessor :lcov,
+ :path,
+ :git_dir,
+ :compare,
+ :syntax_version,
+ :glob_allow_filters,
+ :glob_reject_filters
+
def initialize
# TODO: use run modes
# TODO: use formatters
@run_mode = RUN_MODE_DIFF_STRICT
@enabled_formatters = [OUTPUT_STDOUT]
# set defaults
self.path = '.'
self.git_dir = '.git'
+ self.glob_allow_filters = DEFAULT_FILE_INCLUDE_GLOBS
+ self.glob_reject_filters = []
end
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
def parse(args)
args = build_opts(args)
@@ -49,13 +59,11 @@
lcov_path_option(opts)
project_path_option(opts)
git_dir_option(opts)
compare_option(opts)
ruby_syntax_option(opts)
- # TODO: parse dem other options and assign to self
- # --quiet (skip progress bar)
- # --exit-status (do not print report, just exit)
+ file_filters(opts)
end.parse(args)
guess_lcov_path unless lcov
self
end
@@ -116,8 +124,21 @@
end
def guess_lcov_path
cwd = Pathname.new(File.expand_path(path))
self.lcov = File.join(cwd, 'coverage', 'lcov', "#{cwd.split.last}.lcov")
+ end
+
+ def file_filters(parser)
+ desc = 'Include files matching specified glob patterns (comma separated). ' \
+ "Defaults to '#{DEFAULT_FILE_INCLUDE_GLOBS.join(',')}'"
+ parser.on('-f', '--include-files globs', desc) do |comma_separated_globs|
+ self.glob_allow_filters = comma_separated_globs.strip.split(',')
+ end
+
+ desc = 'Skip files matching specified glob patterns (comma separated). Empty by default.'
+ parser.on('-x', '--exclude-files globs', desc) do |comma_separated_globs|
+ self.glob_reject_filters = comma_separated_globs.strip.split(',')
+ end
end
end
end