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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 59c90b4b800268fd5d50b49faf97dc27e5f4f49c
4
- data.tar.gz: a9431bc1cab5e5fe25d2cbe6b43da73fad6d5bf6
3
+ metadata.gz: d2f7b1ba2cfc19fc71ac84ab1f2b65e6f50fab63
4
+ data.tar.gz: 270c4fbe0609fae2af52c9f5bc0d1b70f00304e5
5
5
  SHA512:
6
- metadata.gz: deb1374c2e661f5efd72f91e37bc506fe2f923299769191a84eb66c00952820f70dae04d61ee1252fc81c1775f1d33aa3f6756992cc2478b220380a6e360cfde
7
- data.tar.gz: 2cd66a62b2bd1682f882c4c13bd0540b95e2ef4d27303bae6bd1029c4c526aa96d20a580598c4028feb84142246096cb32328d811c2e180b31eed1bf439b1cac
6
+ metadata.gz: 4808003cfd6d836c4a627bce6b31bb88115f301a0d41347c7e56f352b22fec95d4469a1d94eed904335f842f21517ce1fa09234add15e79a42423146035e8925
7
+ data.tar.gz: 624cf0658f0f4badf70aa4297d1f2e0fef84c576bad0f43e6aae9350536fe4003a530fb47bb84b24aab45532927823d706cee9e31d30c0f3268887922ec1ddc0
data/.gitignore CHANGED
@@ -11,3 +11,4 @@
11
11
  /lib/querly/pattern/parser.rb
12
12
  parser.output
13
13
  /Gemfile.lock
14
+ .querly_history
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.13.0 (2018-08-27)
6
+
7
+ * Make history file location configurable through `QUERLY_HOME` (defaults to `~/.querly`)
8
+ * Save `console` history (@gfx) #47
9
+
5
10
  ## 0.12.0 (2018-08-03)
6
11
 
7
12
  * Declare MIT license #44
@@ -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
- Console.new(paths: paths.empty? ? [Pathname.pwd] : paths.map {|path| Pathname(path) }).start
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"
@@ -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
- loop
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 loop
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
- line = pair.node.loc.first_line
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[line-1]
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}:#{line}:#{start_col}\t#{src}"
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:
@@ -1,3 +1,3 @@
1
1
  module Querly
2
- VERSION = "0.12.0"
2
+ VERSION = "0.13.0"
3
3
  end
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.12.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-03 00:00:00.000000000 Z
11
+ date: 2018-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler