lib/csscss/cli.rb in csscss-0.2.1 vs lib/csscss/cli.rb in csscss-1.0.0
- old
+ new
@@ -1,13 +1,15 @@
module Csscss
class CLI
def initialize(argv)
- @argv = argv
- @verbose = false
- @color = true
- @minimum = 3
- @compass = false
+ @argv = argv
+ @verbose = false
+ @color = true
+ @minimum = 3
+ @compass = false
+ @ignored_properties = []
+ @ignored_selectors = []
end
def run
parse(@argv)
execute
@@ -38,11 +40,13 @@
end
else
open(filename) {|f| f.read }
end
- RedundancyAnalyzer.new(contents).redundancies(@minimum)
+ RedundancyAnalyzer.new(contents).redundancies(minimum: @minimum,
+ ignored_properties: @ignored_properties,
+ ignored_selectors: @ignored_selectors)
end
combined_redundancies = all_redundancies.inject({}) do |combined, redundancies|
if combined.empty?
redundancies
@@ -59,12 +63,17 @@
report = Reporter.new(combined_redundancies).report(verbose:@verbose, color:true)
puts report unless report.empty?
end
rescue Parslet::ParseFailed => e
- puts "Had a problem parsing the css"
- puts e.cause.ascii_tree
+ line, column = e.cause.source.line_and_column
+ puts "Had a problem parsing the css at line: #{line}, column: #{column}".red
+ if ENV['CSSCSS_DEBUG'] == 'true'
+ puts e.cause.ascii_tree.red
+ else
+ puts "Run with CSSCSS_DEBUG=true for verbose parser errors".red
+ end
exit 1
end
def parse(argv)
opts = OptionParser.new do |opts|
@@ -79,9 +88,17 @@
@color = c
end
opts.on("-n", "--num N", Integer, "Print matches with at least this many rules. Defaults to 3") do |n|
@minimum = n
+ end
+
+ opts.on("--ignore-properties property1,property2,...", Array, "Ignore these properties when finding matches") do |ignored_properties|
+ @ignored_properties = ignored_properties
+ end
+
+ opts.on('--ignore-selectors "selector1","selector2",...', Array, "Ignore these selectors when finding matches") do |ignored_selectors|
+ @ignored_selectors = ignored_selectors
end
opts.on("-V", "--version", "Show version") do |v|
puts opts.ver
exit