Class: Querly::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/querly/cli.rb,
lib/querly/cli/test.rb,
lib/querly/cli/console.rb,
lib/querly/cli/formatter.rb

Defined Under Namespace

Modules: Formatter Classes: Console, Test

Instance Method Summary collapse

Instance Method Details

#check(*paths) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/querly/cli.rb', line 9

def check(*paths)
  require 'querly/cli/formatter'

  formatter = case options[:format]
              when "text"
                Formatter::Text.new
              when "json"
                Formatter::JSON.new
              end
  formatter.start

  begin
    unless config_path.file?
      STDERR.puts <<-Message
Configuration file #{config_path} does not look a file.
Specify configuration file by --config option.
      Message
      exit 1
    end

    config = Config.new
    begin
      config.add_file config_path
    rescue => exn
      formatter.config_error config_path, exn
      exit
    end

    analyzer = Analyzer.new(taggings: config.taggings)
    analyzer.rules.concat config.rules

    ScriptEnumerator.new(paths: paths.map {|path| Pathname(path) }, preprocessors: config.preprocessors).each do |path, script|
      case script
      when Script
        analyzer.scripts << script
        formatter.script_load script
      when StandardError, LoadError
        formatter.script_error path, script
      end
    end

    analyzer.run do |script, rule, pair|
      formatter.issue_found script, rule, pair
    end
  rescue => exn
    formatter.fatal_error exn
    exit 1
  ensure
    formatter.finish
  end
end

#console(*paths) ⇒ Object



62
63
64
65
# File 'lib/querly/cli.rb', line 62

def console(*paths)
  require 'querly/cli/console'
  Console.new(paths: paths.map {|path| Pathname(path) }).start
end

#testObject



69
70
71
72
# File 'lib/querly/cli.rb', line 69

def test()
  require "querly/cli/test"
  Test.new(config_path: config_path).run
end