lib/scss_lint/cli.rb in scss-lint-0.7.1 vs lib/scss_lint/cli.rb in scss-lint-0.9.0
- old
+ new
@@ -1,6 +1,5 @@
-require 'scss_lint'
require 'optparse'
module SCSSLint
class CLI
attr_accessor :options
@@ -20,24 +19,33 @@
opts.on('-e', '--exclude file,...', Array,
'List of file names to exclude') do |files|
options[:excluded_files] = files
end
- opts.on('-i', '--ignore-linter linter,...', Array,
+ opts.on('-i', '--include-linter linter,...', Array,
+ 'Specify which linters you want to run') do |linters|
+ options[:included_linters] = linters
+ end
+
+ opts.on('-x', '--exclude-linter linter,...', Array,
"Specify which linters you don't want to run") do |linters|
- options[:ignored_linters] = linters
+ options[:excluded_linters] = linters
end
+ opts.on_tail('--show-linters', 'Shows available linters') do
+ print_linters
+ end
+
opts.on_tail('-h', '--help', 'Show this message') do
print_help opts.help
end
opts.on_tail('-v', '--version', 'Show version') do
print_version opts.program_name, VERSION
end
- opts.on('-x', '--xml', 'Output the results in XML format') do
+ opts.on('--xml', 'Output the results in XML format') do
options[:reporter] = SCSSLint::Reporter::XMLReporter
end
end
begin
@@ -53,11 +61,11 @@
def run
runner = Runner.new(options)
runner.run(find_files)
report_lints(runner.lints)
halt 1 if runner.lints?
- rescue NoFilesError, NoSuchLinter => ex
+ rescue NoFilesError, NoSuchLinter, Errno::ENOENT => ex
puts ex.message
halt -1
end
private
@@ -73,9 +81,23 @@
def report_lints(lints)
sorted_lints = lints.sort_by { |l| [l.filename, l.line] }
reporter = options.fetch(:reporter, Reporter::DefaultReporter).new(sorted_lints)
output = reporter.report_lints
print output if output
+ end
+
+ def print_linters
+ puts 'Installed linters:'
+
+ linter_names = LinterRegistry.linters.map do |linter|
+ linter.name.split('::').last
+ end
+
+ linter_names.sort.each do |linter_name|
+ puts " - #{linter_name}"
+ end
+
+ halt
end
def print_help(help_message, err = nil)
puts err, '' if err
puts help_message