findr 0.0.7 → 0.0.8.pre1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/lib/findr/cli.rb +57 -37
- data/lib/findr/version.rb +1 -1
- data/pkg/findr-0.0.7.gem +0 -0
- data/pkg/findr-0.0.8.pre1.gem +0 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b6de1fc5f3d2a5d0cb4cc25098d1fdad726ba1c7ce531e75a451792a9f403545
|
4
|
+
data.tar.gz: d5f0341e4712ed3d25ccff81cb0a6ef6902bdee32bb08927b0f15cfcb0267fc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e7b0a90bbc0739009df34e8813687931e01a9febfebe80df569b9c835cb29b8aaae292a507dd80608f4b64667e30c82ad0089e7c6006e4c75a18c0f61a2cc41
|
7
|
+
data.tar.gz: 6d3493e7cbc56f1b7c5820dba8106927e52765c1736bc8c80e3fcbe3698fc0d5b4f067d221ccb11e6c9d1f16cd005f17b2c02963e98f57a292a37b9645c9ee81
|
data/lib/findr/cli.rb
CHANGED
@@ -5,6 +5,7 @@ require 'optparse'
|
|
5
5
|
require 'yaml'
|
6
6
|
require 'pp'
|
7
7
|
|
8
|
+
|
8
9
|
module Findr
|
9
10
|
|
10
11
|
class CLI
|
@@ -16,6 +17,7 @@ module Findr
|
|
16
17
|
end
|
17
18
|
|
18
19
|
def red(text); colorize(text, 31); end
|
20
|
+
def light_red(text); colorize(text, 91); end
|
19
21
|
def green(text); colorize(text, 32); end
|
20
22
|
def yellow(text); colorize(text, 33); end
|
21
23
|
def blue(text); colorize(text, 34); end
|
@@ -136,6 +138,7 @@ module Findr
|
|
136
138
|
verbose "Building file tree..."
|
137
139
|
files = Pathname.glob("#{options[:gglob]}")
|
138
140
|
verbose [' ', files.count, ' files found.']
|
141
|
+
stats[:exceptions] = 0
|
139
142
|
files.each do |current_file|
|
140
143
|
next unless current_file.file?
|
141
144
|
verbose ["Reading file ", current_file]
|
@@ -145,48 +148,62 @@ module Findr
|
|
145
148
|
linenumber = 0
|
146
149
|
tempfile = Tempfile.new( 'current_file.basename' ) and verbose([' Create tempfile ',tempfile.path]) if options[:replace] && options[:force]
|
147
150
|
clear_context(); print_post_context = 0
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
break
|
158
|
-
end
|
159
|
-
linenumber += 1
|
160
|
-
if l=~ options[:find]
|
161
|
-
stats[:local_hits] += 1
|
162
|
-
if firstmatch
|
163
|
-
stdout.puts red("#{current_file.cleanpath}:")
|
164
|
-
end
|
165
|
-
if @context_lines > 0
|
166
|
-
pop_context.map do |linenumber, l|
|
167
|
-
print_line( linenumber, l, coding, false )
|
151
|
+
begin
|
152
|
+
current_file.each_line do |l|
|
153
|
+
begin
|
154
|
+
l, coding = coder.decode(l)
|
155
|
+
rescue Encoder::Error
|
156
|
+
stdout.puts red "Skipping file #{current_file} because of error on line #{linenumber}: #{$!.original.class} #{$!.original.message}"
|
157
|
+
if tempfile
|
158
|
+
tempfile_path = tempfile.path
|
159
|
+
tempfile.unlink and verbose([' Delete tempfile ', tempfile_path])
|
168
160
|
end
|
169
|
-
|
161
|
+
break
|
170
162
|
end
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
163
|
+
linenumber += 1
|
164
|
+
if l=~ options[:find]
|
165
|
+
stats[:local_hits] += 1
|
166
|
+
if firstmatch
|
167
|
+
stdout.puts red("#{current_file.cleanpath}:")
|
168
|
+
end
|
169
|
+
if @context_lines > 0
|
170
|
+
pop_context.map do |linenumber, l|
|
171
|
+
print_line( linenumber, l, coding, false )
|
172
|
+
end
|
173
|
+
print_post_context = @context_lines
|
174
|
+
end
|
175
|
+
print_line( linenumber, l.gsub( /(#{options[:find]})/, bold('\1') ), coding, :bold )
|
176
|
+
firstmatch = false
|
177
|
+
if options[:replace]
|
178
|
+
l_repl = l.gsub( options[:find], options[:replace] )
|
179
|
+
tempfile.puts coder.encode(l_repl, coding) if tempfile
|
180
|
+
replacement_done = true
|
181
|
+
print_line( linenumber, l_repl, coding, :blue )
|
182
|
+
end
|
186
183
|
else
|
187
|
-
|
184
|
+
if tempfile
|
185
|
+
tempfile.puts coder.encode(l, coding)
|
186
|
+
end
|
187
|
+
if print_post_context > 0
|
188
|
+
print_post_context -= 1
|
189
|
+
print_line( linenumber, l, coding )
|
190
|
+
else
|
191
|
+
push_context([linenumber, l])
|
192
|
+
end
|
188
193
|
end
|
189
194
|
end
|
195
|
+
rescue SystemCallError
|
196
|
+
puts light_red "EXCEPTION: #$!"
|
197
|
+
stats[:exceptions] += 1
|
198
|
+
next
|
199
|
+
rescue SignalException
|
200
|
+
puts light_red "\n#{$!.class} received."
|
201
|
+
return
|
202
|
+
ensure
|
203
|
+
if tempfile
|
204
|
+
tempfile.close
|
205
|
+
tempfile.unlink
|
206
|
+
end
|
190
207
|
end
|
191
208
|
if tempfile
|
192
209
|
tempfile.close
|
@@ -207,6 +224,9 @@ module Findr
|
|
207
224
|
|
208
225
|
# some statistics
|
209
226
|
stdout.puts green( "#{stats[:total_hits]} occurences (lines) in #{stats[:hit_files]} of #{stats[:total_files]} files found." )
|
227
|
+
if stats[:exceptions] > 0
|
228
|
+
stdout.puts light_red( "#{stats[:exceptions]} exceptions occurenced." )
|
229
|
+
end
|
210
230
|
end
|
211
231
|
|
212
232
|
def print_line( linenumber, line, coding, color = nil )
|
data/lib/findr/version.rb
CHANGED
data/pkg/findr-0.0.7.gem
CHANGED
Binary file
|
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: findr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8.pre1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Markus Strauss
|
@@ -89,6 +89,7 @@ files:
|
|
89
89
|
- lib/findr/strategy_proxy.rb
|
90
90
|
- lib/findr/version.rb
|
91
91
|
- pkg/findr-0.0.7.gem
|
92
|
+
- pkg/findr-0.0.8.pre1.gem
|
92
93
|
- spec/findr/encoder_spec.rb
|
93
94
|
- spec/spec_helper.rb
|
94
95
|
homepage: https://github.com/mstrauss/findr
|
@@ -106,12 +107,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
107
|
version: 1.8.7
|
107
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
109
|
requirements:
|
109
|
-
- - "
|
110
|
+
- - ">"
|
110
111
|
- !ruby/object:Gem::Version
|
111
|
-
version:
|
112
|
+
version: 1.3.1
|
112
113
|
requirements: []
|
113
114
|
rubyforge_project:
|
114
|
-
rubygems_version: 2.
|
115
|
+
rubygems_version: 2.7.6
|
115
116
|
signing_key:
|
116
117
|
specification_version: 4
|
117
118
|
summary: A ruby find and replace tool for mass editing text files.
|