querly 0.12.0 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +5 -0
- data/lib/querly/cli.rb +16 -1
- data/lib/querly/cli/console.rb +33 -6
- data/lib/querly/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2f7b1ba2cfc19fc71ac84ab1f2b65e6f50fab63
|
4
|
+
data.tar.gz: 270c4fbe0609fae2af52c9f5bc0d1b70f00304e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4808003cfd6d836c4a627bce6b31bb88115f301a0d41347c7e56f352b22fec95d4469a1d94eed904335f842f21517ce1fa09234add15e79a42423146035e8925
|
7
|
+
data.tar.gz: 624cf0658f0f4badf70aa4297d1f2e0fef84c576bad0f43e6aae9350536fe4003a530fb47bb84b24aab45532927823d706cee9e31d30c0f3268887922ec1ddc0
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/lib/querly/cli.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
require "thor"
|
2
2
|
require "json"
|
3
3
|
|
4
|
+
if ENV["NO_COLOR"]
|
5
|
+
Rainbow.enabled = false
|
6
|
+
end
|
7
|
+
|
4
8
|
module Querly
|
5
9
|
class CLI < Thor
|
6
10
|
desc "check [paths]", "Check paths based on configuration"
|
@@ -65,7 +69,18 @@ Specify configuration file by --config option.
|
|
65
69
|
desc "console [paths]", "Start console for given paths"
|
66
70
|
def console(*paths)
|
67
71
|
require 'querly/cli/console'
|
68
|
-
|
72
|
+
home_path = if (path = ENV["QUERLY_HOME"])
|
73
|
+
Pathname(path)
|
74
|
+
else
|
75
|
+
Pathname(Dir.home) + ".querly"
|
76
|
+
end
|
77
|
+
home_path.mkdir unless home_path.exist?
|
78
|
+
|
79
|
+
Console.new(
|
80
|
+
paths: paths.empty? ? [Pathname.pwd] : paths.map {|path| Pathname(path) },
|
81
|
+
history_path: home_path + "history",
|
82
|
+
history_size: ENV["QUERLY_HISTORY_SIZE"]&.to_i || 1_000_000
|
83
|
+
).start
|
69
84
|
end
|
70
85
|
|
71
86
|
desc "test", "Check configuration"
|
data/lib/querly/cli/console.rb
CHANGED
@@ -6,9 +6,15 @@ module Querly
|
|
6
6
|
include Concerns::BacktraceFormatter
|
7
7
|
|
8
8
|
attr_reader :paths
|
9
|
+
attr_reader :history_path
|
10
|
+
attr_reader :history_size
|
11
|
+
attr_reader :history
|
9
12
|
|
10
|
-
def initialize(paths:)
|
13
|
+
def initialize(paths:, history_path:, history_size:)
|
11
14
|
@paths = paths
|
15
|
+
@history_path = history_path
|
16
|
+
@history_size = history_size
|
17
|
+
@history = []
|
12
18
|
end
|
13
19
|
|
14
20
|
def start
|
@@ -24,7 +30,8 @@ Querly #{VERSION}, interactive console
|
|
24
30
|
reload!
|
25
31
|
STDOUT.puts " ready!"
|
26
32
|
|
27
|
-
|
33
|
+
load_history
|
34
|
+
start_loop
|
28
35
|
end
|
29
36
|
|
30
37
|
def reload!
|
@@ -50,7 +57,7 @@ Querly #{VERSION}, interactive console
|
|
50
57
|
@analyzer
|
51
58
|
end
|
52
59
|
|
53
|
-
def
|
60
|
+
def start_loop
|
54
61
|
while line = Readline.readline("> ", true)
|
55
62
|
case line
|
56
63
|
when "quit"
|
@@ -68,22 +75,24 @@ Querly #{VERSION}, interactive console
|
|
68
75
|
|
69
76
|
analyzer.find(pattern) do |script, pair|
|
70
77
|
path = script.path.to_s
|
71
|
-
|
78
|
+
line_no = pair.node.loc.first_line
|
72
79
|
range = pair.node.loc.expression
|
73
80
|
start_col = range.column
|
74
81
|
end_col = range.last_column
|
75
82
|
|
76
|
-
src = range.source_buffer.source_lines[
|
83
|
+
src = range.source_buffer.source_lines[line_no-1]
|
77
84
|
src = Rainbow(src[0...start_col]).blue +
|
78
85
|
Rainbow(src[start_col...end_col]).bright.blue.bold +
|
79
86
|
Rainbow(src[end_col..-1]).blue
|
80
87
|
|
81
|
-
puts " #{path}:#{
|
88
|
+
puts " #{path}:#{line_no}:#{start_col}\t#{src}"
|
82
89
|
|
83
90
|
count += 1
|
84
91
|
end
|
85
92
|
|
86
93
|
puts "#{count} results"
|
94
|
+
|
95
|
+
save_history line
|
87
96
|
rescue => exn
|
88
97
|
STDOUT.puts Rainbow("Error: #{exn}").red
|
89
98
|
STDOUT.puts "Backtrace:"
|
@@ -95,6 +104,24 @@ Querly #{VERSION}, interactive console
|
|
95
104
|
end
|
96
105
|
end
|
97
106
|
|
107
|
+
def load_history
|
108
|
+
history_path.readlines.each do |line|
|
109
|
+
line.chomp!
|
110
|
+
Readline::HISTORY.push(line)
|
111
|
+
history.push line
|
112
|
+
end
|
113
|
+
rescue Errno::ENOENT
|
114
|
+
# in the first time
|
115
|
+
end
|
116
|
+
|
117
|
+
def save_history(line)
|
118
|
+
history.push line
|
119
|
+
if history.size > history_size
|
120
|
+
@history = history.drop(history.size - history_size)
|
121
|
+
end
|
122
|
+
history_path.write(history.join("\n") + "\n")
|
123
|
+
end
|
124
|
+
|
98
125
|
def puts_commands
|
99
126
|
puts <<-Message
|
100
127
|
Commands:
|
data/lib/querly/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: querly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Soutaro Matsumoto
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|