Class: Fdlint::CLI::Runner

Inherits:
Object show all
Includes:
Helper::Logger
Defined in:
lib/fdlint/cli.rb

Constant Summary

Constants included from Helper::Logger

Helper::Logger::LEVELS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper::Logger

#log, #logger

Constructor Details

#initialize(options = {}) ⇒ Runner

Returns a new instance of Runner.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fdlint/cli.rb', line 29

def initialize( options={} )

  @options  = options
  @files    = options[:files]
  # 默认不检查已经被压缩的文件
  @checkmin = options[:checkmin]

  # Windows 下默认是ANSI编码
  # 我们需要使用 UTF-8 编码输出
  IO.popen "chcp 65001" if ENV['OS'] =~ /windows/i

  $logger = Logger.new(STDOUT).tap do |l|
    l.level = options[:debug] ? Logger::DEBUG : Logger::FATAL
  end
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



27
28
29
# File 'lib/fdlint/cli.rb', line 27

def files
  @files
end

#optionsObject (readonly)

Returns the value of attribute options.



27
28
29
# File 'lib/fdlint/cli.rb', line 27

def options
  @options
end

Instance Method Details

#list_rulesObject



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fdlint/cli.rb', line 56

def list_rules
  ::Fdlint::Rule.rules.each do |syntax, rules|
    puts "----> #{syntax} (#{rules.size})\n\n"
    rules.each do |rule|
      print " " * 6
      print rule
      print "\n"
    end
    print "\n"
  end
end

#runObject



45
46
47
48
49
50
51
52
53
54
# File 'lib/fdlint/cli.rb', line 45

def run

  trap("SIGINT") { puts "\nGoodbye!"; exit! }

  if text = @options[:text]
    validate_content
  elsif !@files.empty?
    validate_files
  end
end