term_utils 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/COPYING +1 -1
- data/Rakefile +6 -0
- data/doc/TermUtils/AP/Article.html +13 -13
- data/doc/TermUtils/AP/ArticleResult.html +4 -4
- data/doc/TermUtils/AP/Flag.html +8 -8
- data/doc/TermUtils/AP/Parameter.html +9 -9
- data/doc/TermUtils/AP/ParameterResult.html +4 -4
- data/doc/TermUtils/AP/ParameterWalkerHooks.html +4 -4
- data/doc/TermUtils/AP/ParseError.html +646 -14
- data/doc/TermUtils/AP/Parser.html +43 -15
- data/doc/TermUtils/AP/Result.html +4 -4
- data/doc/TermUtils/AP/Syntax.html +4 -4
- data/doc/TermUtils/AP/SyntaxError.html +4 -86
- data/doc/TermUtils/AP/Walker.html +4 -4
- data/doc/TermUtils/AP.html +16 -16
- data/doc/TermUtils/FF/Config.html +8 -8
- data/doc/TermUtils/FF/Context.html +4 -4
- data/doc/TermUtils/FF/Entry.html +4 -4
- data/doc/TermUtils/FF/Finder.html +850 -0
- data/doc/TermUtils/FF/FinderEntry.html +1191 -0
- data/doc/TermUtils/FF/FinderQuery.html +946 -0
- data/doc/TermUtils/FF/Query.html +11 -15
- data/doc/TermUtils/FF.html +131 -7
- data/doc/TermUtils/PropertyTreeNode.html +6 -6
- data/doc/TermUtils/Tab/Column.html +44 -44
- data/doc/TermUtils/Tab/Header.html +19 -19
- data/doc/TermUtils/Tab/Holder.html +40 -40
- data/doc/TermUtils/Tab/Printer.html +4 -4
- data/doc/TermUtils/Tab/Table.html +59 -59
- data/doc/TermUtils/Tab/TableError.html +4 -86
- data/doc/TermUtils/Tab.html +42 -42
- data/doc/TermUtils.html +6 -6
- data/doc/_index.html +29 -23
- data/doc/class_list.html +1 -1
- data/doc/css/style.css +1 -0
- data/doc/file.README.html +25 -21
- data/doc/frames.html +1 -1
- data/doc/index.html +25 -21
- data/doc/method_list.html +385 -89
- data/doc/top-level-namespace.html +4 -4
- data/lib/term_utils/ap/article.rb +2 -2
- data/lib/term_utils/ap/flag.rb +2 -2
- data/lib/term_utils/ap/parameter.rb +2 -2
- data/lib/term_utils/ap/parser.rb +16 -15
- data/lib/term_utils/ap/result.rb +2 -2
- data/lib/term_utils/ap/syntax.rb +2 -2
- data/lib/term_utils/ap.rb +66 -22
- data/lib/term_utils/ff/config.rb +3 -3
- data/lib/term_utils/ff/entry.rb +2 -2
- data/lib/term_utils/ff/finder.rb +255 -0
- data/lib/term_utils/ff/query.rb +6 -8
- data/lib/term_utils/ff.rb +4 -3
- data/lib/term_utils/property_tree_node.rb +3 -3
- data/lib/term_utils/tab.rb +14 -13
- data/lib/term_utils.rb +2 -2
- data/term_utils.gemspec +2 -2
- metadata +8 -5
- data/doc/TermUtils/AP/NoSuchValueError.html +0 -217
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
Top Level Namespace
|
8
8
|
|
9
|
-
— Documentation by YARD 0.9.
|
9
|
+
— Documentation by YARD 0.9.34
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -100,9 +100,9 @@
|
|
100
100
|
</div>
|
101
101
|
|
102
102
|
<div id="footer">
|
103
|
-
Generated on
|
104
|
-
<a href="
|
105
|
-
0.9.
|
103
|
+
Generated on Wed Aug 9 17:34:25 2023 by
|
104
|
+
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
105
|
+
0.9.34 (ruby-3.2.2).
|
106
106
|
</div>
|
107
107
|
|
108
108
|
</div>
|
data/lib/term_utils/ap/flag.rb
CHANGED
data/lib/term_utils/ap/parser.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (C)
|
3
|
+
# Copyright (C) 2023 Thomas Baron
|
4
4
|
#
|
5
5
|
# This file is part of term_utils.
|
6
6
|
#
|
@@ -27,7 +27,8 @@ module TermUtils
|
|
27
27
|
# Parses a given list of arguments.
|
28
28
|
# @param syntax [Syntax]
|
29
29
|
# @param arguments [Array<String>]
|
30
|
-
# @param opts [Hash]
|
30
|
+
# @param opts [Hash<Symbol, Object>]
|
31
|
+
# @option opts [Boolean] :strict Whether the Syntax must be considered as strict.
|
31
32
|
# @return [Result]
|
32
33
|
# @raise [ParseError]
|
33
34
|
# @raise [SyntaxError]
|
@@ -52,7 +53,7 @@ module TermUtils
|
|
52
53
|
shortcut_flags.each do |label, flag|
|
53
54
|
next unless arg.start_with? label
|
54
55
|
|
55
|
-
return [flag.label, arg[label.length
|
56
|
+
return [flag.label, arg[label.length..]]
|
56
57
|
end
|
57
58
|
|
58
59
|
nil
|
@@ -96,7 +97,7 @@ module TermUtils
|
|
96
97
|
unless flagged_params.key? arguments.first
|
97
98
|
# Unknown flag
|
98
99
|
# End of parsing
|
99
|
-
raise TermUtils::AP::ParseError
|
100
|
+
raise TermUtils::AP::ParseError.new(message: 'flagged parameter unexpected', fault: arguments.first) if opts.fetch(:strict, false)
|
100
101
|
|
101
102
|
break
|
102
103
|
end
|
@@ -104,7 +105,7 @@ module TermUtils
|
|
104
105
|
param = flagged_params[arguments.first]
|
105
106
|
if param.occur_bounded? && (fp_occ[param.id] >= param.max_occurs)
|
106
107
|
# Max occurs reached
|
107
|
-
raise TermUtils::AP::ParseError
|
108
|
+
raise TermUtils::AP::ParseError.new(message: 'occur limit reached', parameter: param.id, fault: arguments.first) if opts.fetch(:strict, false)
|
108
109
|
|
109
110
|
break
|
110
111
|
end
|
@@ -117,7 +118,7 @@ module TermUtils
|
|
117
118
|
# Unflagged
|
118
119
|
if unflagged_params.empty?
|
119
120
|
# End of parsing
|
120
|
-
raise TermUtils::AP::ParseError
|
121
|
+
raise TermUtils::AP::ParseError.new(message: 'unflagged parameter unexpected', fault: arguments.first) if opts.fetch(:strict, false)
|
121
122
|
|
122
123
|
break
|
123
124
|
end
|
@@ -125,7 +126,7 @@ module TermUtils
|
|
125
126
|
param = unflagged_params.first
|
126
127
|
if arguments.first == '--'
|
127
128
|
# End of parameter
|
128
|
-
raise TermUtils::AP::ParseError
|
129
|
+
raise TermUtils::AP::ParseError.new(message: 'parameter not consumed', parameter: param.id) if up_occ < param.min_occurs
|
129
130
|
|
130
131
|
arguments.shift
|
131
132
|
unflagged_params.shift
|
@@ -137,7 +138,7 @@ module TermUtils
|
|
137
138
|
param_res = TermUtils::AP::ParameterResult.new(result, param)
|
138
139
|
case parse0_param(param_res, param, arguments)
|
139
140
|
when :esc_param
|
140
|
-
raise TermUtils::AP::ParseError
|
141
|
+
raise TermUtils::AP::ParseError.new(message: 'parameter not consumed', parameter: param.id) if up_occ < param.min_occurs
|
141
142
|
|
142
143
|
unflagged_params.shift
|
143
144
|
up_occ = 0
|
@@ -153,7 +154,7 @@ module TermUtils
|
|
153
154
|
syntax.parameters.each do |p|
|
154
155
|
next if result.find_parameters(p.id).length >= p.min_occurs
|
155
156
|
|
156
|
-
raise TermUtils::AP::ParseError
|
157
|
+
raise TermUtils::AP::ParseError.new(message: 'parameter not consumed', parameter: p.id)
|
157
158
|
end
|
158
159
|
end
|
159
160
|
|
@@ -170,15 +171,15 @@ module TermUtils
|
|
170
171
|
|
171
172
|
if arguments.empty?
|
172
173
|
# End of arguments
|
173
|
-
raise TermUtils::AP::ParseError
|
174
|
-
raise TermUtils::AP::ParseError
|
174
|
+
raise TermUtils::AP::ParseError.new(message: 'article not consumed', parameter: param.id) if occ < arts.first.min_occurs
|
175
|
+
raise TermUtils::AP::ParseError.new(message: 'article not consumed', parameter: param.id) if self.class.eval_article_min_occurs(arts[1..]) > 0
|
175
176
|
|
176
177
|
break
|
177
178
|
end
|
178
179
|
|
179
180
|
if arguments.first == '-'
|
180
181
|
# End of article
|
181
|
-
raise TermUtils::AP::ParseError
|
182
|
+
raise TermUtils::AP::ParseError.new(message: 'article not consumed', parameter: param.id) if occ < arts.first.min_occurs
|
182
183
|
|
183
184
|
arguments.shift
|
184
185
|
arts.shift
|
@@ -186,8 +187,8 @@ module TermUtils
|
|
186
187
|
next
|
187
188
|
elsif arguments.first.start_with? '-'
|
188
189
|
# End of parameter
|
189
|
-
raise TermUtils::AP::ParseError
|
190
|
-
raise TermUtils::AP::ParseError
|
190
|
+
raise TermUtils::AP::ParseError.new(message: 'article not consumed', parameter: param.id) if occ < arts.first.min_occurs
|
191
|
+
raise TermUtils::AP::ParseError.new(message: 'article not consumed', parameter: param.id) if self.class.eval_article_min_occurs(arts[1..]) > 0
|
191
192
|
|
192
193
|
if arguments.first == '--'
|
193
194
|
arguments.shift
|
data/lib/term_utils/ap/result.rb
CHANGED
data/lib/term_utils/ap/syntax.rb
CHANGED
data/lib/term_utils/ap.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (C)
|
3
|
+
# Copyright (C) 2023 Thomas Baron
|
4
4
|
#
|
5
5
|
# This file is part of term_utils.
|
6
6
|
#
|
@@ -16,28 +16,79 @@
|
|
16
16
|
# You should have received a copy of the GNU General Public License
|
17
17
|
# along with term_utils. If not, see <https://www.gnu.org/licenses/>.
|
18
18
|
|
19
|
+
require 'term_utils/ap/article'
|
20
|
+
require 'term_utils/ap/flag'
|
21
|
+
require 'term_utils/ap/parameter'
|
22
|
+
require 'term_utils/ap/syntax'
|
23
|
+
require 'term_utils/ap/result'
|
24
|
+
require 'term_utils/ap/parser'
|
25
|
+
|
19
26
|
module TermUtils
|
20
27
|
# The Argument Parser module provides a way to parse arguments.
|
21
28
|
module AP
|
22
|
-
# NoSuchValueError.
|
23
|
-
class NoSuchValueError < StandardError
|
24
|
-
def initialize(msg)
|
25
|
-
super
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
29
|
# ParseError.
|
30
30
|
class ParseError < StandardError
|
31
|
-
|
32
|
-
|
31
|
+
# Constructs a new ParseError.
|
32
|
+
# @param props [Hash<Symbol, Object>]
|
33
|
+
def initialize(props = {})
|
34
|
+
super(self.class.create_message(props))
|
35
|
+
@props = props.dup
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns the properties associated to this one.
|
39
|
+
# @return [Hash<Symbol, Object>]
|
40
|
+
def props
|
41
|
+
@props.dup
|
42
|
+
end
|
43
|
+
|
44
|
+
# Returns the short message (i.e. the message without properties).
|
45
|
+
# @return [String] The short message.
|
46
|
+
def short_message
|
47
|
+
@props.fetch(:message)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Tests whether this one has a syntax parameter ID.
|
51
|
+
# @return [Boolean]
|
52
|
+
def parameter?
|
53
|
+
@props.key?(:parameter)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Returns the syntax parameter ID (if any).
|
57
|
+
# @return [Symbol, nil] The syntax parameter ID if any, `nil` otherwise.
|
58
|
+
def parameter
|
59
|
+
@props.fetch(:parameter, nil)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Tests whether this one has a faulty argument.
|
63
|
+
# @return [Boolean]
|
64
|
+
def fault?
|
65
|
+
@props.key?(:fault)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Returns the faulty argument (if any).
|
69
|
+
# @return [String, nil] The faulty argument if any, `nil` otherwise.
|
70
|
+
def fault
|
71
|
+
@props.fetch(:fault, nil)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Creates a message based on given properties.
|
75
|
+
# @param props [Hash<Symbol, Object>]
|
76
|
+
# @return [String]
|
77
|
+
def self.create_message(props)
|
78
|
+
props = props.dup
|
79
|
+
msg = props.delete(:message) { |key| raise StandardError, "#{key} property is mandatory" }
|
80
|
+
return msg if props.empty?
|
81
|
+
|
82
|
+
vals = []
|
83
|
+
props.each do |key, val|
|
84
|
+
vals << "#{key}: \"#{val}\""
|
85
|
+
end
|
86
|
+
"#{msg} (#{vals.join(', ')})"
|
33
87
|
end
|
34
88
|
end
|
35
89
|
|
36
90
|
# SyntaxError.
|
37
91
|
class SyntaxError < StandardError
|
38
|
-
def initialize(msg)
|
39
|
-
super
|
40
|
-
end
|
41
92
|
end
|
42
93
|
|
43
94
|
# Creates a new Syntax.
|
@@ -52,7 +103,7 @@ module TermUtils
|
|
52
103
|
# @param syntax [Syntax]
|
53
104
|
# @param arguments [Array<String>]
|
54
105
|
# @param opts [Hash]
|
55
|
-
# @option opts [Boolean] :strict Whether the Syntax must be considered strict.
|
106
|
+
# @option opts [Boolean] :strict Whether the Syntax must be considered as strict.
|
56
107
|
# @return [Result]
|
57
108
|
# @raise [ParseError]
|
58
109
|
# @raise [SyntaxError]
|
@@ -61,10 +112,3 @@ module TermUtils
|
|
61
112
|
end
|
62
113
|
end
|
63
114
|
end
|
64
|
-
|
65
|
-
require 'term_utils/ap/article'
|
66
|
-
require 'term_utils/ap/flag'
|
67
|
-
require 'term_utils/ap/parameter'
|
68
|
-
require 'term_utils/ap/syntax'
|
69
|
-
require 'term_utils/ap/result'
|
70
|
-
require 'term_utils/ap/parser'
|
data/lib/term_utils/ff/config.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (C)
|
3
|
+
# Copyright (C) 2023 Thomas Baron
|
4
4
|
#
|
5
5
|
# This file is part of term_utils.
|
6
6
|
#
|
@@ -47,8 +47,8 @@ module TermUtils
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def initialize_copy(other)
|
50
|
-
@ignore_list = other.ignore_list.dup
|
51
50
|
super
|
51
|
+
@ignore_list = @ignore_list.dup
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
data/lib/term_utils/ff/entry.rb
CHANGED
@@ -0,0 +1,255 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (C) 2023 Thomas Baron
|
4
|
+
#
|
5
|
+
# This file is part of term_utils.
|
6
|
+
#
|
7
|
+
# term_utils is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License as published by
|
9
|
+
# the Free Software Foundation, version 3 of the License.
|
10
|
+
#
|
11
|
+
# term_utils is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with term_utils. If not, see <https://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
module TermUtils
|
20
|
+
module FF
|
21
|
+
# Represents filesystem Entry.
|
22
|
+
class FinderEntry
|
23
|
+
# @return [Integer]
|
24
|
+
attr_accessor :index
|
25
|
+
# @return [String]
|
26
|
+
attr_accessor :name
|
27
|
+
# Identifies the type of stat. The return string is one of: “file”,
|
28
|
+
# “directory”, “characterSpecial”, “blockSpecial”, “fifo”, “link”,
|
29
|
+
# “socket”, or “unknown”.
|
30
|
+
# @return [String]
|
31
|
+
attr_accessor :kind
|
32
|
+
# Returns the numeric user id of the owner of stat.
|
33
|
+
# @return [Integer]
|
34
|
+
attr_accessor :uid
|
35
|
+
# Returns the numeric group id of the owner of stat.
|
36
|
+
# @return [Integer]
|
37
|
+
attr_accessor :gid
|
38
|
+
# Returns an integer representing the permission bits of stat. The meaning
|
39
|
+
# of the bits is platform dependent.
|
40
|
+
# @return [Integer]
|
41
|
+
attr_accessor :mode
|
42
|
+
# Returns the size of stat in bytes.
|
43
|
+
# @return [Integer]
|
44
|
+
attr_accessor :size
|
45
|
+
# @return [Array<String>]
|
46
|
+
attr_accessor :path_parts
|
47
|
+
# @return [String]
|
48
|
+
attr_accessor :path
|
49
|
+
|
50
|
+
def initialize
|
51
|
+
@index = nil
|
52
|
+
@name = nil
|
53
|
+
@kind = nil
|
54
|
+
@path_parts = nil
|
55
|
+
@path = nil
|
56
|
+
end
|
57
|
+
|
58
|
+
def directory?
|
59
|
+
@kind == 'directory'
|
60
|
+
end
|
61
|
+
|
62
|
+
def file?
|
63
|
+
@kind == 'file'
|
64
|
+
end
|
65
|
+
|
66
|
+
# @return [Integer]
|
67
|
+
def depth
|
68
|
+
@path_parts.length
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# Represents a Query.
|
73
|
+
class FinderQuery
|
74
|
+
# @return [Integer]
|
75
|
+
attr_accessor :min_depth
|
76
|
+
# @return [Integer, nil]
|
77
|
+
attr_accessor :max_depth
|
78
|
+
# @return [Boolean]
|
79
|
+
attr_accessor :use_stat
|
80
|
+
# @return [String, Array<String>, nil]
|
81
|
+
attr_accessor :entry_kind
|
82
|
+
|
83
|
+
def initialize
|
84
|
+
@min_depth = 0
|
85
|
+
@max_depth = nil
|
86
|
+
@use_stat = false
|
87
|
+
@entry_kind = nil
|
88
|
+
@filters = []
|
89
|
+
end
|
90
|
+
|
91
|
+
def filter(kind, &block)
|
92
|
+
raise StandardError, 'wrong filter kind' unless %i[enter skip include exclude].include?(kind)
|
93
|
+
raise StandardError, "missing #{kind} block" if block.nil?
|
94
|
+
|
95
|
+
@filters << { kind: kind, block: block }
|
96
|
+
end
|
97
|
+
|
98
|
+
# Wether to enter a directory.
|
99
|
+
def enter_directory(&block)
|
100
|
+
filter(:enter, &block)
|
101
|
+
end
|
102
|
+
|
103
|
+
# Wether not to enter a directory.
|
104
|
+
def skip_directory(&block)
|
105
|
+
filter(:skip, &block)
|
106
|
+
end
|
107
|
+
|
108
|
+
# Wether to include an entry into the results.
|
109
|
+
def include_entry(&block)
|
110
|
+
filter(:include, &block)
|
111
|
+
end
|
112
|
+
|
113
|
+
# Wether to exclue an entry from the results.
|
114
|
+
def exclude_entry(&block)
|
115
|
+
filter(:exclude, &block)
|
116
|
+
end
|
117
|
+
|
118
|
+
def each_filter(&block)
|
119
|
+
@filters.each(&block)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
# Represents the find method engine.
|
124
|
+
class Finder
|
125
|
+
attr_reader :query
|
126
|
+
|
127
|
+
def initialize(paths)
|
128
|
+
@paths = paths.dup
|
129
|
+
@query = FinderQuery.new
|
130
|
+
end
|
131
|
+
|
132
|
+
def exec
|
133
|
+
@paths.each_with_object([]) do |path, obj|
|
134
|
+
ctx = { entries: obj, basedir: path }
|
135
|
+
list_start(ctx)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def list_start(ctx)
|
140
|
+
entry = FinderEntry.new.tap do |e|
|
141
|
+
e.index = ctx[:entries].length
|
142
|
+
e.name = File.basename(ctx[:basedir])
|
143
|
+
if @query.use_stat
|
144
|
+
st = File.stat(ctx[:basedir])
|
145
|
+
e.kind = st.ftype
|
146
|
+
e.uid = st.uid
|
147
|
+
e.gid = st.gid
|
148
|
+
e.mode = st.mode
|
149
|
+
e.size = st.size
|
150
|
+
end
|
151
|
+
e.path_parts = []
|
152
|
+
e.path = ctx[:basedir]
|
153
|
+
end
|
154
|
+
ctx[:entries] << entry if match?(entry) && include?(entry)
|
155
|
+
return unless enter?(entry)
|
156
|
+
|
157
|
+
list(ctx)
|
158
|
+
end
|
159
|
+
|
160
|
+
def list(ctx)
|
161
|
+
path_parts = ctx.fetch(:path_parts, [])
|
162
|
+
absolute_path =
|
163
|
+
if path_parts.empty?
|
164
|
+
ctx[:basedir]
|
165
|
+
else
|
166
|
+
"#{ctx[:basedir]}/#{path_parts.join('/')}"
|
167
|
+
end
|
168
|
+
entries = Dir.entries(absolute_path)
|
169
|
+
entries.each do |name|
|
170
|
+
next if %w[. ..].include?(name)
|
171
|
+
|
172
|
+
entry = FinderEntry.new.tap do |e|
|
173
|
+
e.index = ctx[:entries].length
|
174
|
+
e.name = name
|
175
|
+
if @query.use_stat
|
176
|
+
st = File.stat("#{absolute_path}/#{name}")
|
177
|
+
e.kind = st.ftype
|
178
|
+
e.uid = st.uid
|
179
|
+
e.gid = st.gid
|
180
|
+
e.mode = st.mode
|
181
|
+
e.size = st.size
|
182
|
+
end
|
183
|
+
e.path_parts = path_parts.dup + [name]
|
184
|
+
e.path = "#{ctx[:basedir]}/#{e.path_parts.join('/')}"
|
185
|
+
end
|
186
|
+
ctx[:entries] << entry if match?(entry) && include?(entry)
|
187
|
+
if enter?(entry)
|
188
|
+
list(ctx.merge({ path_parts: entry.path_parts }))
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
def match?(entry)
|
194
|
+
# (1of2) Depth
|
195
|
+
return false if entry.depth < @query.min_depth
|
196
|
+
return false if !@query.max_depth.nil? && entry.depth > @query.max_depth
|
197
|
+
|
198
|
+
# (2of2) Entry kind.
|
199
|
+
if @query.entry_kind.nil?
|
200
|
+
true
|
201
|
+
elsif @query.entry_kind.is_a?(String)
|
202
|
+
entry.kind == @query.entry_kind
|
203
|
+
elsif @query.entry_kind.is_a?(Array)
|
204
|
+
@query.entry_kind.include?(entry.kind)
|
205
|
+
else
|
206
|
+
false
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
def enter?(entry)
|
211
|
+
unless @query.use_stat
|
212
|
+
return File.directory?(entry.path)
|
213
|
+
end
|
214
|
+
|
215
|
+
return false unless entry.directory?
|
216
|
+
|
217
|
+
@query.each_filter do |f|
|
218
|
+
case f[:kind]
|
219
|
+
when :enter
|
220
|
+
return true if f[:block].call(entry)
|
221
|
+
when :skip
|
222
|
+
return false if f[:block].call(entry)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
true
|
226
|
+
end
|
227
|
+
|
228
|
+
def include?(entry)
|
229
|
+
@query.each_filter do |f|
|
230
|
+
case f[:kind]
|
231
|
+
when :include
|
232
|
+
return true if f[:block].call(entry)
|
233
|
+
when :exclude
|
234
|
+
return false if f[:block].call(entry)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
true
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
# Finds files.
|
242
|
+
# @param paths [Array<String>]
|
243
|
+
# @return [Array<Hash>]
|
244
|
+
def self.find(*paths, &block)
|
245
|
+
fdr =
|
246
|
+
if paths.empty?
|
247
|
+
TermUtils::FF::Finder.new(['.'])
|
248
|
+
else
|
249
|
+
TermUtils::FF::Finder.new(paths)
|
250
|
+
end
|
251
|
+
block&.call(fdr.query)
|
252
|
+
fdr.exec
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
data/lib/term_utils/ff/query.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (C)
|
3
|
+
# Copyright (C) 2023 Thomas Baron
|
4
4
|
#
|
5
5
|
# This file is part of term_utils.
|
6
6
|
#
|
@@ -28,11 +28,11 @@ module TermUtils
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def initialize_copy(other)
|
31
|
-
@config = other.config.dup
|
32
31
|
super
|
32
|
+
@config = @config.dup
|
33
33
|
end
|
34
34
|
|
35
|
-
# Adds a Regexp
|
35
|
+
# Adds a Regexp for ignoring file names.
|
36
36
|
# @param regexp [Regexp]
|
37
37
|
# @return [Query]
|
38
38
|
def ignore(regexp)
|
@@ -133,10 +133,8 @@ module TermUtils
|
|
133
133
|
# @param name [String]
|
134
134
|
# @return [Boolean]
|
135
135
|
def self.accept_entry_name?(ctx, name)
|
136
|
-
ctx.config.ignore_list.each do |
|
137
|
-
if
|
138
|
-
return false
|
139
|
-
end
|
136
|
+
ctx.config.ignore_list.each do |e|
|
137
|
+
return false if e.match?(name)
|
140
138
|
end
|
141
139
|
true
|
142
140
|
end
|
data/lib/term_utils/ff.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (C)
|
3
|
+
# Copyright (C) 2023 Thomas Baron
|
4
4
|
#
|
5
5
|
# This file is part of term_utils.
|
6
6
|
#
|
@@ -17,7 +17,7 @@
|
|
17
17
|
# along with term_utils. If not, see <https://www.gnu.org/licenses/>.
|
18
18
|
|
19
19
|
module TermUtils
|
20
|
-
# Provides
|
20
|
+
# Provides ways to find files.
|
21
21
|
module FF
|
22
22
|
end
|
23
23
|
end
|
@@ -25,3 +25,4 @@ end
|
|
25
25
|
require 'term_utils/ff/config'
|
26
26
|
require 'term_utils/ff/entry'
|
27
27
|
require 'term_utils/ff/query'
|
28
|
+
require 'term_utils/ff/finder'
|
@@ -1,6 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (C)
|
3
|
+
# Copyright (C) 2023 Thomas Baron
|
4
4
|
#
|
5
5
|
# This file is part of term_utils.
|
6
6
|
#
|
@@ -191,7 +191,7 @@ module TermUtils
|
|
191
191
|
# @return [PropertyTreeNode]
|
192
192
|
def find_node(path)
|
193
193
|
catch :found do
|
194
|
-
each_node(path: path) do |n|
|
194
|
+
each_node(path: path) do |n| # rubocop:disable Lint/UnreachableLoop
|
195
195
|
throw :found, n
|
196
196
|
end
|
197
197
|
nil
|