class Lintrunner::Options
Attributes
options[R]
Public Class Methods
new()
click to toggle source
# File lib/lintrunner/options.rb, line 9 def initialize @options = {} @option_parser = OptionParser.new do |opts| add_banner(opts) add_config_option(opts) add_context_option(opts) add_include_path_option(opts) add_reporter_option(opts) end end
Public Instance Methods
parse(args)
click to toggle source
# File lib/lintrunner/options.rb, line 20 def parse(args) @option_parser.parse!(args) add_defaults options[:path] = args.first if args.first options end
test()
click to toggle source
# File lib/lintrunner/options.rb, line 8 def test; require 'pry'; binding.pry;end
Private Instance Methods
add_config_option(opts)
click to toggle source
# File lib/lintrunner/options.rb, line 45 def add_config_option(opts) message = "the configuration file for lintrunner (default: .lintrunner_config)" opts.on("-c", "--config config", message, String) do |config| self.options[:config] = config end end
add_context_option(opts)
click to toggle source
# File lib/lintrunner/options.rb, line 52 def add_context_option(opts) message = "the path on which lintrunner will execute in (default: current path)" opts.on("-x", "--context path", message, String) do |path| self.options[:context] = Pathname.new(path).realpath.to_s end end
add_defaults()
click to toggle source
# File lib/lintrunner/options.rb, line 29 def add_defaults options[:config] ||= ".lintrunner_config" options[:context] ||= Dir.pwd options[:include_paths] = Array(options[:include_paths]) << options[:context] options[:include_paths].uniq! options[:reporter] ||= "text" options[:path] = Dir.pwd end
add_include_path_option(opts)
click to toggle source
# File lib/lintrunner/options.rb, line 59 def add_include_path_option(opts) message = "the paths to add to load paths (the context is in the load path)" opts.on("--include_path path1,...", message, Array) do |paths| self.options[:include_paths] = paths end end
add_reporter_option(opts)
click to toggle source
# File lib/lintrunner/options.rb, line 66 def add_reporter_option(opts) message = "the reporter that lintrunner uses to report results" opts.on("--reporter reporter", message, String) do |reporter| self.options[:reporter] = reporter end end
unindent(str)
click to toggle source
# File lib/lintrunner/options.rb, line 73 def unindent(str) str.gsub(/^#{str.scan(/^[ ]+(?=\S)/).min}/, "") end