utils 0.68.0 → 0.69.0
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/README.md +251 -18
- data/bin/ascii7 +28 -0
- data/bin/blameline +17 -0
- data/bin/changes +69 -5
- data/bin/classify +128 -7
- data/bin/code_comment +102 -104
- data/bin/commit_message +26 -2
- data/bin/create_cstags +18 -0
- data/bin/create_tags +10 -0
- data/bin/discover +38 -1
- data/bin/edit +14 -1
- data/bin/edit_wait +14 -0
- data/bin/enum +139 -15
- data/bin/git-empty +50 -0
- data/bin/git-versions +20 -0
- data/bin/json_check +15 -1
- data/bin/long_lines +11 -2
- data/bin/myex +38 -0
- data/bin/on_change +22 -0
- data/bin/path +21 -0
- data/bin/print_method +29 -1
- data/bin/probe +52 -4
- data/bin/rainbow +52 -0
- data/bin/rd2md +15 -0
- data/bin/search +83 -1
- data/bin/sedit +6 -0
- data/bin/serve +18 -3
- data/bin/ssh-tunnel +14 -2
- data/bin/strip_spaces +17 -9
- data/bin/sync_dir +48 -1
- data/bin/untest +19 -1
- data/bin/utils-utilsrc +42 -6
- data/bin/vcf2alias +33 -0
- data/bin/yaml_check +24 -2
- data/lib/utils/config_dir.rb +127 -0
- data/lib/utils/config_file.rb +445 -1
- data/lib/utils/editor.rb +215 -3
- data/lib/utils/finder.rb +127 -16
- data/lib/utils/grepper.rb +90 -1
- data/lib/utils/irb.rb +387 -39
- data/lib/utils/line_blamer.rb +28 -0
- data/lib/utils/line_formatter.rb +198 -0
- data/lib/utils/md5.rb +14 -0
- data/lib/utils/patterns.rb +77 -3
- data/lib/utils/probe_server.rb +302 -23
- data/lib/utils/ssh_tunnel_specification.rb +58 -0
- data/lib/utils/version.rb +1 -1
- data/lib/utils/xt/source_location_extension.rb +18 -6
- data/lib/utils.rb +3 -1
- data/tests/utils_test.rb +7 -1
- data/utils.gemspec +5 -5
- metadata +4 -6
- data/bin/number_files +0 -26
- data/lib/utils/xdg_config.rb +0 -10
- /data/{COPYING → LICENSE} +0 -0
data/lib/utils/grepper.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'term/ansicolor'
|
2
|
-
require 'tins/xt'
|
3
2
|
|
4
3
|
class Utils::Grepper
|
5
4
|
include Tins::Find
|
@@ -7,16 +6,36 @@ class Utils::Grepper
|
|
7
6
|
include Term::ANSIColor
|
8
7
|
|
9
8
|
class Queue
|
9
|
+
# The initialize method sets up a new instance with the specified maximum
|
10
|
+
# size and empty data array.
|
11
|
+
#
|
12
|
+
# @param max_size [ Integer ] the maximum size limit for the data storage
|
10
13
|
def initialize(max_size)
|
11
14
|
@max_size, @data = max_size, []
|
12
15
|
end
|
13
16
|
|
17
|
+
# The max_size reader method provides access to the maximum size value.
|
18
|
+
#
|
19
|
+
# @return [ Integer ] the maximum size value stored in the instance
|
14
20
|
attr_reader :max_size
|
15
21
|
|
22
|
+
# The data method returns a duplicate of the internal data array.
|
23
|
+
#
|
24
|
+
# This method provides access to the internal @data instance variable by
|
25
|
+
# returning a shallow copy of the array, ensuring that external
|
26
|
+
# modifications do not affect the original data structure.
|
27
|
+
#
|
28
|
+
# @return [ Array ] a duplicate of the internal data array
|
16
29
|
def data
|
17
30
|
@data.dup
|
18
31
|
end
|
19
32
|
|
33
|
+
# The push method adds an element to the queue and removes the oldest
|
34
|
+
# element if the maximum size is exceeded.
|
35
|
+
#
|
36
|
+
# @param x [ Object ] the element to be added to the queue
|
37
|
+
#
|
38
|
+
# @return [ Queue ] returns self to allow for method chaining
|
20
39
|
def push(x)
|
21
40
|
@data.shift if @data.size > @max_size
|
22
41
|
@data << x
|
@@ -25,6 +44,22 @@ class Utils::Grepper
|
|
25
44
|
alias << push
|
26
45
|
end
|
27
46
|
|
47
|
+
# The initialize method sets up the grepper instance with the provided
|
48
|
+
# options.
|
49
|
+
#
|
50
|
+
# This method configures the grepper by processing the input options, setting up
|
51
|
+
# the root directories for searching, initializing the configuration, and
|
52
|
+
# preparing pattern matchers for filename and skip patterns. It also handles
|
53
|
+
# queue initialization for buffering output when specified.
|
54
|
+
#
|
55
|
+
# @param opts [ Hash ] the options hash containing configuration settings
|
56
|
+
# @option opts [ Hash ] :args the command-line arguments
|
57
|
+
# @option opts [ Array ] :roots the root directories to search
|
58
|
+
# @option opts [ Utils::ConfigFile ] :config the configuration file object
|
59
|
+
# @option opts [ Hash ] :pattern the pattern-related options
|
60
|
+
#
|
61
|
+
# @return [ Utils::Grepper ] a new grepper instance configured with the
|
62
|
+
# provided options
|
28
63
|
def initialize(opts = {})
|
29
64
|
@args = opts[:args] || {}
|
30
65
|
@roots = discover_roots(opts[:roots])
|
@@ -56,10 +91,32 @@ class Utils::Grepper
|
|
56
91
|
end
|
57
92
|
end
|
58
93
|
|
94
|
+
# The paths reader method provides access to the paths instance variable.
|
95
|
+
#
|
96
|
+
# @return [ Array ] the array of paths stored in the instance variable
|
59
97
|
attr_reader :paths
|
60
98
|
|
99
|
+
# The pattern reader method provides access to the pattern matcher object.
|
100
|
+
#
|
101
|
+
# This method returns the internal pattern matcher that was initialized
|
102
|
+
# during object creation, allowing external code to interact with the pattern
|
103
|
+
# matching functionality directly.
|
104
|
+
#
|
105
|
+
# @return [ Utils::Patterns::Pattern ] the pattern matcher object used for
|
106
|
+
# matching operations
|
61
107
|
attr_reader :pattern
|
62
108
|
|
109
|
+
# The match method processes a file to find matching content based on
|
110
|
+
# configured patterns.
|
111
|
+
# It handles directory pruning, file skipping, and various output formats
|
112
|
+
# depending on the configuration.
|
113
|
+
# The method opens files for reading, applies pattern matching, and manages
|
114
|
+
# output through different code paths.
|
115
|
+
# It supports features like line-based searching, git blame integration, and
|
116
|
+
# multiple output modes.
|
117
|
+
# The method returns the instance itself to allow for method chaining.
|
118
|
+
#
|
119
|
+
# @return [ Utils::Grepper ] returns self to allow for method chaining
|
63
120
|
def match(filename)
|
64
121
|
@filename = filename
|
65
122
|
@output = []
|
@@ -108,6 +165,15 @@ class Utils::Grepper
|
|
108
165
|
self
|
109
166
|
end
|
110
167
|
|
168
|
+
# The match_lines method processes each line from a file using pattern
|
169
|
+
# matching.
|
170
|
+
#
|
171
|
+
# This method iterates through lines in the provided file, applying pattern
|
172
|
+
# matching to identify relevant content. It handles various output options
|
173
|
+
# based on command-line arguments and manages queuing of lines for context
|
174
|
+
# display.
|
175
|
+
#
|
176
|
+
# @param file [IO] the file object to be processed line by line
|
111
177
|
def match_lines(file)
|
112
178
|
for line in file
|
113
179
|
if m = @pattern.match(line)
|
@@ -148,6 +214,16 @@ class Utils::Grepper
|
|
148
214
|
end
|
149
215
|
end
|
150
216
|
|
217
|
+
# The search method performs a file search operation within specified roots,
|
218
|
+
# filtering results based on various criteria including file extensions,
|
219
|
+
# pruning directories, and skipping specific files.
|
220
|
+
#
|
221
|
+
# It utilizes a visit lambda to determine whether each file or directory
|
222
|
+
# should be processed or skipped based on configuration settings and
|
223
|
+
# command-line arguments. The method employs the find utility to traverse
|
224
|
+
# the filesystem, executing match operations on qualifying files.
|
225
|
+
#
|
226
|
+
# @return [ Utils::Grepper ] returns self to allow for method chaining
|
151
227
|
def search
|
152
228
|
suffixes = Array(@args[?I])
|
153
229
|
visit = -> filename {
|
@@ -175,6 +251,19 @@ class Utils::Grepper
|
|
175
251
|
|
176
252
|
private
|
177
253
|
|
254
|
+
# The discover_roots method processes an array of root patterns and expands
|
255
|
+
# them into actual directory paths.
|
256
|
+
#
|
257
|
+
# This method takes an array of root patterns, which may include glob
|
258
|
+
# patterns, and uses Dir[r] to expand each pattern into matching directory
|
259
|
+
# paths.
|
260
|
+
# It handles the case where the input roots array is nil by defaulting to an
|
261
|
+
# empty array. The expanded paths are then concatenated into a single result
|
262
|
+
# array.
|
263
|
+
#
|
264
|
+
# @param roots [ Array<String>, nil ] an array of root patterns or nil
|
265
|
+
#
|
266
|
+
# @return [ Array<String> ] an array of expanded directory paths matching the input patterns
|
178
267
|
def discover_roots(roots)
|
179
268
|
roots ||= []
|
180
269
|
roots.inject([]) { |rs, r| rs.concat Dir[r] }
|