lib/slim_lint/options.rb in slim_lint-0.2.0 vs lib/slim_lint/options.rb in slim_lint-0.3.0
- old
+ new
@@ -28,16 +28,12 @@
ex.backtrace
end
private
+ # Register linter-related flags.
def add_linter_options(parser)
- parser.on('-e', '--exclude file,...', Array,
- 'List of file names to exclude') do |files|
- @options[:excluded_files] = files
- end
-
parser.on('-i', '--include-linter linter,...', Array,
'Specify which linters you want to run') do |linters|
@options[:included_linters] = linters
end
@@ -46,14 +42,27 @@
@options[:excluded_linters] = linters
end
parser.on('-r', '--reporter reporter', String,
'Specify which reporter you want to use to generate the output') do |reporter|
- @options[:reporter] = SlimLint::Reporter.const_get("#{reporter.capitalize}Reporter")
+ @options[:reporter] = load_reporter_class(reporter.capitalize)
end
end
+ # Returns the class of the specified Reporter.
+ #
+ # @param reporter_name [String]
+ # @raise [SlimLint::Exceptions::InvalidCLIOption] if reporter doesn't exist
+ # @return [Class]
+ def load_reporter_class(reporter_name)
+ SlimLint::Reporter.const_get("#{reporter_name}Reporter")
+ rescue NameError
+ raise SlimLint::Exceptions::InvalidCLIOption,
+ "#{reporter_name}Reporter does not exist"
+ end
+
+ # Register file-related flags.
def add_file_options(parser)
parser.on('-c', '--config config-file', String,
'Specify which configuration file you want to use') do |conf_file|
@options[:config_file] = conf_file
end
@@ -62,9 +71,10 @@
'List of file names to exclude') do |files|
@options[:excluded_files] = files
end
end
+ # Register informational flags.
def add_info_options(parser)
parser.on('--show-linters', 'Display available linters') do
@options[:show_linters] = true
end