class Undercover::Options
Constants
- OUTPUT_FORMATTERS
- RUN_MODE
Attributes
compare[RW]
git_dir[RW]
lcov[RW]
path[RW]
syntax_version[RW]
Public Class Methods
new()
click to toggle source
# File lib/undercover/options.rb, line 22 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' end
Public Instance Methods
parse(args)
click to toggle source
rubocop:disable Metrics/MethodLength, Metrics/AbcSize
# File lib/undercover/options.rb, line 33 def parse(args) args = build_opts(args) OptionParser.new do |opts| opts.banner = 'Usage: undercover [options]' opts.on_tail('-h', '--help', 'Prints this help') do puts(opts) exit end opts.on_tail('--version', 'Show version') do puts VERSION exit end 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) end.parse(args) guess_lcov_path unless lcov self end
Private Instance Methods
args_from_options_file(path)
click to toggle source
# File lib/undercover/options.rb, line 74 def args_from_options_file(path) return [] unless File.exist?(path) File.read(path).split('\n').flat_map(&:split) end
build_opts(args)
click to toggle source
rubocop:enable Metrics/MethodLength, Metrics/AbcSize
# File lib/undercover/options.rb, line 66 def build_opts(args) project_options.concat(args) end
compare_option(parser)
click to toggle source
# File lib/undercover/options.rb, line 103 def compare_option(parser) desc = 'Generate coverage warnings for all changes after `ref`' parser.on('-c', '--compare ref', desc) do |ref| self.compare = ref end end
git_dir_option(parser)
click to toggle source
# File lib/undercover/options.rb, line 96 def git_dir_option(parser) desc = 'Override `.git` with a custom directory' parser.on('-g', '--git-dir dir', desc) do |dir| self.git_dir = dir end end
guess_lcov_path()
click to toggle source
# File lib/undercover/options.rb, line 118 def guess_lcov_path cwd = Pathname.new(File.expand_path(path)) self.lcov = File.join(cwd, 'coverage', 'lcov', "#{cwd.split.last}.lcov") end
lcov_path_option(parser)
click to toggle source
# File lib/undercover/options.rb, line 84 def lcov_path_option(parser) parser.on('-l', '--lcov path', 'LCOV report file path') do |path| self.lcov = path end end
project_options()
click to toggle source
# File lib/undercover/options.rb, line 70 def project_options args_from_options_file(project_options_file) end
project_options_file()
click to toggle source
# File lib/undercover/options.rb, line 80 def project_options_file './.undercover' end
project_path_option(parser)
click to toggle source
# File lib/undercover/options.rb, line 90 def project_path_option(parser) parser.on('-p', '--path path', 'Project directory') do |path| self.path = path end end
ruby_syntax_option(parser)
click to toggle source
# File lib/undercover/options.rb, line 110 def ruby_syntax_option(parser) versions = Imagen::AVAILABLE_RUBY_VERSIONS.sort.join(', ') desc = "Ruby syntax version, one of: #{versions}" parser.on('-r', '--ruby-syntax ver', desc) do |version| self.syntax_version = version.strip end end