Class: CSSFilter::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/cssfilter.rb

Overview

Simple Command line interface for CSSFilter.

It can be configured via a YAML file.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI

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_fileObject (readonly)

Returns the value of attribute config_file.



229
230
231
# File 'lib/cssfilter.rb', line 229

def config_file
  @config_file
end

#optionsObject (readonly)

Returns the value of attribute options.



231
232
233
# File 'lib/cssfilter.rb', line 231

def options
  @options
end

Class Method Details

.runObject



225
226
227
# File 'lib/cssfilter.rb', line 225

def self.run
  new.run
end

Instance Method Details

#parserObject



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

#runObject



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(options).filter(css)
    end
  rescue => error
    raise error if $DEBUG
    $stderr.puts error
  end
end