Class: Querly::CLI

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

Defined Under Namespace

Modules: Formatter Classes: Console, Rules, Test

Instance Method Summary collapse

Instance Method Details

#check(*paths) ⇒ Object



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
60
61
62
# File 'lib/querly/cli.rb', line 10

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 "Configuration file \#{config_path} does not look a file.\nSpecify configuration file by --config option.\n      Message\n      exit 1\n    end\n\n    root_option = options[:root]\n    root_path = root_option ? Pathname(root_option).realpath : config_path.parent.realpath\n\n    config = begin\n      yaml = YAML.load(config_path.read)\n      Config.load(yaml, config_path: config_path, root_dir: root_path, stderr: STDERR)\n    rescue => exn\n      formatter.config_error config_path, exn\n      exit\n    end\n\n    analyzer = Analyzer.new(config: config)\n\n    ScriptEnumerator.new(paths: paths.map {|path| Pathname(path) }, config: config).each do |path, script|\n      case script\n      when Script\n        analyzer.scripts << script\n        formatter.script_load script\n      when StandardError, LoadError\n        formatter.script_error path, script\n      end\n    end\n\n    analyzer.run do |script, rule, pair|\n      formatter.issue_found script, rule, pair\n    end\n  rescue => exn\n    formatter.fatal_error exn\n    exit 1\n  ensure\n    formatter.finish\n  end\nend\n"

#console(*paths) ⇒ Object



65
66
67
68
# File 'lib/querly/cli.rb', line 65

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

#rules(*ids) ⇒ Object



79
80
81
82
# File 'lib/querly/cli.rb', line 79

def rules(*ids)
  require "querly/cli/rules"
  Rules.new(config_path: config_path, ids: ids).run
end

#testObject



72
73
74
75
# File 'lib/querly/cli.rb', line 72

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

#versionObject



85
86
87
# File 'lib/querly/cli.rb', line 85

def version
  puts "Querly #{VERSION}"
end