fif 0.4.3 → 0.5.1
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 +4 -4
- data/bin/fif +7 -3
- data/lib/fif.rb +15 -30
- data/lib/fif/dumb_search.rb +30 -0
- data/lib/fif/search.rb +30 -0
- data/lib/fif/version.rb +3 -0
- metadata +7 -5
- data/test/test_fif.rb +0 -84
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6392ab6e3a51332c3ab2bfb306b1f2cffd692f13
|
|
4
|
+
data.tar.gz: 911fab3a6f71f4dd3434cabd716b92b7fe2cf6ac
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 45404cba95e761476fcf9f9f2164adf0151d762d1a6ddb9da338da7976278a748afa68568395b02708915743b40e3977d8a0d9551f12b7a6a1445afbdc464a93
|
|
7
|
+
data.tar.gz: 38f87079b73aa595ada3abe3dfdcd19e1d59f65a180fd8d754727be35f8f9909497fcfe1ba40dde0a6096341015d9836a5fd601b21a2abc7b801ce366a3a7842
|
data/bin/fif
CHANGED
|
@@ -9,6 +9,7 @@ options = {
|
|
|
9
9
|
:dumb => false,
|
|
10
10
|
:regex_opts => 0,
|
|
11
11
|
:fregex_opts => 0,
|
|
12
|
+
:folder => '.'
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
banner = <<-eos
|
|
@@ -24,6 +25,10 @@ begin
|
|
|
24
25
|
OptionParser.new do |o|
|
|
25
26
|
o.banner = banner
|
|
26
27
|
|
|
28
|
+
o.on('-f', '--folder [FOLDER]', 'Run in FOLDER, instead of the current directory.') do |f|
|
|
29
|
+
options[:folder] = f
|
|
30
|
+
end
|
|
31
|
+
|
|
27
32
|
o.on('-c', '--colour', 'Disable coloured output.') do |c|
|
|
28
33
|
options[:colour] = false
|
|
29
34
|
end
|
|
@@ -65,11 +70,10 @@ rescue OptionParser::InvalidOption
|
|
|
65
70
|
exit
|
|
66
71
|
end
|
|
67
72
|
|
|
73
|
+
trap("SIGINT") { exit! }
|
|
74
|
+
|
|
68
75
|
if ARGV.empty?
|
|
69
76
|
puts "Missing argument(s), see `fif --help`."
|
|
70
|
-
elsif options[:dumb]
|
|
71
|
-
Fif.dumb_search(ARGV, options) { |result| puts result }
|
|
72
77
|
else
|
|
73
|
-
p options
|
|
74
78
|
Fif.search(ARGV, options) { |result| puts result }
|
|
75
79
|
end
|
data/lib/fif.rb
CHANGED
|
@@ -1,45 +1,30 @@
|
|
|
1
1
|
require 'fif/utils'
|
|
2
|
+
require 'fif/search'
|
|
3
|
+
require 'fif/dumb_search'
|
|
2
4
|
|
|
3
5
|
require 'pathname'
|
|
4
6
|
|
|
5
7
|
class Fif
|
|
6
8
|
def self.search(arguments, options)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Dir.recurse('.') do |file|
|
|
10
|
-
if arguments[1] == nil || fregex.match(file)
|
|
11
|
-
if not File.binary?(file)
|
|
12
|
-
f = File.new(file)
|
|
13
|
-
f.each do |line|
|
|
14
|
-
begin
|
|
15
|
-
if regex.match(line)
|
|
16
|
-
line.gsub!(regex, '\1'.green) if options[:colour]
|
|
17
|
-
yield "#{file}:#{f.lineno}:\t#{line}"
|
|
18
|
-
end
|
|
19
|
-
rescue ArgumentError
|
|
20
|
-
puts "Ignoring unreadable file: #{file}"
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
9
|
+
klass = options[:dumb] ? DumbSearch : Search
|
|
10
|
+
s = klass.new(arguments, options)
|
|
27
11
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
line[arguments[0]] = arguments[0].green if options[:colour]
|
|
36
|
-
yield "#{file}:#{f.lineno}:\t#{line}"
|
|
12
|
+
Dir.recurse(options[:folder]) do |file|
|
|
13
|
+
if s.file_match(file) && !File.binary?(file)
|
|
14
|
+
f = File.new(file)
|
|
15
|
+
f.each do |line|
|
|
16
|
+
begin
|
|
17
|
+
if s.line_match(line)
|
|
18
|
+
yield "#{file}:#{f.lineno}:\t#{s.line_format(line)}"
|
|
37
19
|
end
|
|
20
|
+
rescue ArgumentError
|
|
21
|
+
puts "Ignoring unreadable file: #{file}"
|
|
38
22
|
end
|
|
39
23
|
end
|
|
40
24
|
end
|
|
41
25
|
end
|
|
26
|
+
|
|
42
27
|
end
|
|
43
28
|
end
|
|
44
29
|
|
|
45
|
-
class OptionCombinationError <
|
|
30
|
+
class OptionCombinationError < StandardError; end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
class Fif
|
|
2
|
+
class DumbSearch
|
|
3
|
+
def initialize(arguments, options)
|
|
4
|
+
@options = options
|
|
5
|
+
|
|
6
|
+
@file = arguments[1]
|
|
7
|
+
@line = arguments[0]
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def file_match(file)
|
|
11
|
+
if @file
|
|
12
|
+
file[@file]
|
|
13
|
+
else
|
|
14
|
+
true
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def line_match(line)
|
|
19
|
+
line[@line]
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def line_format(line)
|
|
23
|
+
if @options[:colour]
|
|
24
|
+
line[@line] = @line.green
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
line
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
data/lib/fif/search.rb
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
class Fif
|
|
2
|
+
class Search
|
|
3
|
+
def initialize(arguments, options)
|
|
4
|
+
@options = options
|
|
5
|
+
|
|
6
|
+
@file = Regexp.new(arguments[1], options[:fregex_opts]) if arguments[1]
|
|
7
|
+
@line = Regexp.new("(#{arguments[0]})", options[:regex_opts])
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def file_match(file)
|
|
11
|
+
if @file
|
|
12
|
+
@file.match(file)
|
|
13
|
+
else
|
|
14
|
+
true
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def line_match(line)
|
|
19
|
+
@line.match(line)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def line_format(line)
|
|
23
|
+
if @options[:colour]
|
|
24
|
+
line.gsub!(@line, '\1'.green)
|
|
25
|
+
else
|
|
26
|
+
line
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
data/lib/fif/version.rb
ADDED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fif
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Elliott Hillary
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2013-
|
|
11
|
+
date: 2013-05-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: A Ruby gem for finding stuff in files.
|
|
14
14
|
email: elliotthillary@googlemail.com
|
|
@@ -17,9 +17,11 @@ executables:
|
|
|
17
17
|
extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
|
19
19
|
files:
|
|
20
|
-
- lib/fif.rb
|
|
20
|
+
- lib/fif/dumb_search.rb
|
|
21
|
+
- lib/fif/search.rb
|
|
21
22
|
- lib/fif/utils.rb
|
|
22
|
-
-
|
|
23
|
+
- lib/fif/version.rb
|
|
24
|
+
- lib/fif.rb
|
|
23
25
|
- bin/fif
|
|
24
26
|
homepage: http://github.com/ElliottH/fif
|
|
25
27
|
licenses: []
|
|
@@ -40,7 +42,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
40
42
|
version: '0'
|
|
41
43
|
requirements: []
|
|
42
44
|
rubyforge_project:
|
|
43
|
-
rubygems_version: 2.0.
|
|
45
|
+
rubygems_version: 2.0.3
|
|
44
46
|
signing_key:
|
|
45
47
|
specification_version: 4
|
|
46
48
|
summary: Find in files
|
data/test/test_fif.rb
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
require 'test/unit'
|
|
2
|
-
require 'fif'
|
|
3
|
-
|
|
4
|
-
class FifTest < Test::Unit::TestCase
|
|
5
|
-
def test_search
|
|
6
|
-
results_a, results_b = 0, 0
|
|
7
|
-
|
|
8
|
-
options = {
|
|
9
|
-
:colour => false,
|
|
10
|
-
:regex_opts => 0,
|
|
11
|
-
:fregex_opts => 0,
|
|
12
|
-
}
|
|
13
|
-
arguments = [
|
|
14
|
-
"f[aeiou]f"
|
|
15
|
-
]
|
|
16
|
-
regex = Regexp.new(arguments[0])
|
|
17
|
-
|
|
18
|
-
Fif.search(arguments, options) do |result|
|
|
19
|
-
results_a += 1
|
|
20
|
-
assert regex.match result
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
arguments[1] = ".rb"
|
|
25
|
-
|
|
26
|
-
Fif.search(arguments, options) do |result|
|
|
27
|
-
results_b += 1
|
|
28
|
-
assert regex.match result
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
assert_not_equal results_a, results_b
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
arguments[0] = "F[aeiou]F"
|
|
36
|
-
arguments[1] = nil
|
|
37
|
-
options[:regex_opts] |= Regexp::IGNORECASE
|
|
38
|
-
regex = Regexp.new(arguments[0], Regexp::IGNORECASE)
|
|
39
|
-
results_a, results_b = 0, 0
|
|
40
|
-
|
|
41
|
-
Fif.search(arguments, options) do |result|
|
|
42
|
-
results_a += 1
|
|
43
|
-
assert regex.match result
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
arguments[1] = ".rB"
|
|
47
|
-
options[:fregex_opts] |= Regexp::IGNORECASE
|
|
48
|
-
|
|
49
|
-
Fif.search(arguments, options) do |result|
|
|
50
|
-
results_b += 1
|
|
51
|
-
assert regex.match result
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
assert_not_equal results_a, results_b
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def test_dumb
|
|
59
|
-
results_a, results_b = 0, 0
|
|
60
|
-
|
|
61
|
-
options = {
|
|
62
|
-
:colour => false
|
|
63
|
-
}
|
|
64
|
-
arguments = [
|
|
65
|
-
"fif"
|
|
66
|
-
]
|
|
67
|
-
|
|
68
|
-
Fif.dumb_search(arguments, options) do |result|
|
|
69
|
-
results_a += 1
|
|
70
|
-
assert result.include? arguments[0]
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
arguments[1] = ".rb"
|
|
75
|
-
|
|
76
|
-
Fif.dumb_search(arguments, options) do |result|
|
|
77
|
-
results_b += 1
|
|
78
|
-
assert result.include? arguments[0]
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
assert_not_equal results_a, results_b
|
|
83
|
-
end
|
|
84
|
-
end
|