cql_ruby 0.0.5 → 0.0.6

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
  SHA256:
3
- metadata.gz: 50e03910538e8b57539419210406155ba4a9d0aed14f0852edfd1867e6fbccbe
4
- data.tar.gz: acb0f56f0faefb1f39613f2805b25cbee66e61d0a715138007c021036e05e03a
3
+ metadata.gz: a856d1a192105ae54c8af21e06b28b8653d982b770eed3d7ad7d64b4a62b56e2
4
+ data.tar.gz: e11a83d4c61b8ce16ff9540869cf9d1c4da4664812d20881a0b6455d85875d7a
5
5
  SHA512:
6
- metadata.gz: 71feb8dab0a500e27989d7a96117b2f558b09f1eade1db44503a69ee3cadf6f21bec65d7e921ae219a39835ded528fc62cf91216989a9121006343636098b81b
7
- data.tar.gz: e3fdf1a7ecdc01fb7f5f3174d932a60e4718d2c08534414ec0627666590df1d29985cc113763423a3eb913a0d7994b789d1ad7c8baed645e04fe2b8104ecdb98
6
+ metadata.gz: 1e4c5d6c18e49543ff3776f31bcc42cbb6eb8c2709a9e764dcc947bf43f411725e3e32af7089a9f7059d6e502dc3b155dd94842833a81c557586b39390d5a505
7
+ data.tar.gz: 8317d7378cd86da7ea32b09b9e505eaa461a8f60d87a443e44ed82eafc02d32992d483224a221b2d0558a2796d428088d84bcc8205a74cb00f3adafe3c4a86f1
@@ -16,12 +16,16 @@ def show_help
16
16
  \t\tNesting under: nest:T(=NAME) Example: nest:def=save_user nest:class=UserManager
17
17
 
18
18
  \tOPTIONS
19
+ \t\t-lN (N is integer) Add N surrounding line before and after.
19
20
  \t\t-nc (--no-color) No color on output.
20
21
  \t\t-nf (--no-file) No file names.
21
22
  \t\t-ns (--no-source) No source code.
23
+ \t\t-nr (--no-recursion) Non-recursive search.
24
+ \t\t-v -vv -vvv Debug output levels.
22
25
 
23
26
  \tEXAMPLES
24
- \t\tcql_ruby -ns update_user_info ./ type:send,arg
27
+ \t\tcql_ruby user ./
28
+ \t\tcql_ruby -ns -nr %user_info ./ type:send,arg nest:block nest:class=r/User/i
25
29
  HELP
26
30
 
27
31
  exit
@@ -34,6 +38,7 @@ def extract_options
34
38
  show_file: true,
35
39
  show_source: true,
36
40
  recursive_search: true,
41
+ surrounding_lines: 0,
37
42
  }
38
43
 
39
44
  ARGV.delete_if do |arg|
@@ -51,6 +56,8 @@ def extract_options
51
56
  CqlRuby::Config.debug_level = lvl
52
57
  elsif %w[-nr --no-recursive].include?(arg)
53
58
  options[:recursive_search] = false
59
+ elsif arg[0..1] == '-l' && arg[2..].to_i > 0
60
+ options[:surrounding_lines] = arg[2..].to_i
54
61
  else
55
62
  raise "Unknown arg #{arg}"
56
63
  end
@@ -92,6 +99,7 @@ begin
92
99
  printer.color_on = options[:show_color]
93
100
  printer.file_on = options[:show_file]
94
101
  printer.source_on = options[:show_source]
102
+ printer.surrounding_lines = options[:surrounding_lines]
95
103
 
96
104
  collector = CqlRuby::CrumbCollector.new(printer)
97
105
  CqlRuby::Executor.new(
@@ -8,6 +8,7 @@ module CqlRuby
8
8
  attr_writer :color_on
9
9
  attr_writer :file_on
10
10
  attr_writer :source_on
11
+ attr_writer :surrounding_lines
11
12
 
12
13
  def initialize
13
14
  super
@@ -15,14 +16,33 @@ module CqlRuby
15
16
  @color_on = true
16
17
  @file_on = true
17
18
  @source_on = true
19
+ @surrounding_lines = 0
20
+ @counter = 0
18
21
  end
19
22
 
20
23
  #
21
24
  # @param crumb [Cqlruby::Crumb]
22
25
  #
23
26
  def print(crumb)
24
- puts "#{color(94)}#{crumb.file_name}#{decor_reset}:#{color(33)}#{crumb.line_no}#{decor_reset} #{color(93)}#{crumb.type}#{decor_reset}" if @file_on
25
- puts decorate_source_line(crumb) if @source_on
27
+ parts = "##{color(97)}#{@counter}#{decor_reset}"
28
+ parts += " #{color(94)}#{crumb.file_name}#{decor_reset}:#{color(33)}#{crumb.line_no}#{decor_reset} #{color(93)}#{crumb.type}#{decor_reset}" if @file_on
29
+
30
+ if @source_on && @surrounding_lines.positive?
31
+ parts_visible_len = parts.gsub(/\e\[\d+m/, '').size + 1
32
+ indent = ' ' * parts_visible_len
33
+ (-@surrounding_lines).upto(-1).each { |offs| puts "#{indent}#{crumb.surrounding_line(offs)}" }
34
+ end
35
+
36
+ parts += ' ' + decorate_source_line(crumb) if @source_on
37
+
38
+ puts parts
39
+
40
+ if @source_on && @surrounding_lines.positive?
41
+ 1.upto(@surrounding_lines).each { |offs| puts "#{indent}#{crumb.surrounding_line(offs)}" }
42
+ puts '--'
43
+ end
44
+
45
+ @counter += 1
26
46
  end
27
47
 
28
48
  private
@@ -54,7 +74,6 @@ module CqlRuby
54
74
  # @param [Cqlruby::Crumb] crumb
55
75
  # @return [String]
56
76
  def decorate_source_line(crumb)
57
- # TODO add +- line surrounding options
58
77
  source = crumb.source
59
78
  from = crumb.line_col_no
60
79
  to = from + crumb.expression_size
@@ -63,14 +82,14 @@ module CqlRuby
63
82
  subject = source[from..to - 1] || ''
64
83
  suffix = source[to..] || ''
65
84
 
66
- color(90) +
85
+ color(97) +
67
86
  prefix +
68
87
  decor_reset +
69
88
  color(31) +
70
89
  bold +
71
90
  subject +
72
91
  decor_reset +
73
- color(90) +
92
+ color(97) +
74
93
  suffix +
75
94
  decor_reset
76
95
  end
@@ -58,6 +58,8 @@ module CqlRuby
58
58
  walk(ast, [], source_reader)
59
59
 
60
60
  nil
61
+ rescue => e
62
+ CqlRuby.log "File #{file} cannot be parsed: #{e}"
61
63
  end
62
64
 
63
65
  def walk(node, ancestors, source_reader)
@@ -110,6 +112,10 @@ CqlRuby::Crumb = Struct.new(:full_name, :ancestors, :source_reader) do
110
112
  source_reader.source_line(line_no)
111
113
  end
112
114
 
115
+ def surrounding_line(offset)
116
+ source_reader.source_line(line_no + offset)
117
+ end
118
+
113
119
  def file_name
114
120
  source_reader.file
115
121
  end
@@ -129,6 +135,8 @@ CqlRuby::SourceReader = Struct.new(:file) do
129
135
  end
130
136
 
131
137
  def source_line(n)
138
+ return nil unless lines.size >= n
139
+
132
140
  lines[n - 1].chop
133
141
  end
134
142
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cql_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - itarato