Class: CSSFilter::CLI
- Inherits:
-
Object
- Object
- CSSFilter::CLI
- Defined in:
- lib/cssfilter.rb
Overview
Simple Command line interface for CSSFilter.
It can be configured via a YAML file.
Instance Attribute Summary collapse
-
#config_file ⇒ Object
readonly
Returns the value of attribute config_file.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #parser ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
233 234 235 236 237 |
# File 'lib/cssfilter.rb', line 233 def initialize require 'optparse' @config_file = nil @options = {} end |
Instance Attribute Details
#config_file ⇒ Object (readonly)
Returns the value of attribute config_file.
229 230 231 |
# File 'lib/cssfilter.rb', line 229 def config_file @config_file end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
231 232 233 |
# File 'lib/cssfilter.rb', line 231 def @options end |
Class Method Details
.run ⇒ Object
225 226 227 |
# File 'lib/cssfilter.rb', line 225 def self.run new.run end |
Instance Method Details
#parser ⇒ Object
239 240 241 242 243 244 |
# File 'lib/cssfilter.rb', line 239 def parser OptionParser.new do |opt| opt.on('--config <YAML_FILE>', 'filter with custom configuration'){ |file| @config_file = file } opt.on('--debug', 'run in debug mode to see error details'){ $DEBUG = true } end end |
#run ⇒ Object
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/cssfilter.rb', line 253 def run parser.parse! begin files = ARGV files.each do |f| raise "cssfilter: file not found -- #{f}" unless File.exist?(f) end files.each do |file| css = File.read(file) puts CSSFilter.new().filter(css) end rescue => error raise error if $DEBUG $stderr.puts error end end |