markdown_exec 1.8.7 → 1.8.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +33 -3
- data/Gemfile +1 -0
- data/Gemfile.lock +7 -1
- data/Rakefile +1 -0
- data/bin/bmde +1 -1
- data/bin/tab_completion.sh +4 -4
- data/examples/colors.md +2 -1
- data/examples/indent.md +66 -0
- data/examples/linked.md +20 -1
- data/examples/load1.sh +5 -0
- data/examples/load2.sh +5 -0
- data/examples/nickname.md +26 -0
- data/lib/array.rb +4 -0
- data/lib/cached_nested_file_reader.rb +47 -43
- data/lib/ce_get_cost_and_usage.rb +22 -0
- data/lib/constants.rb +7 -0
- data/lib/exceptions.rb +6 -4
- data/lib/fcb.rb +5 -2
- data/lib/filter.rb +6 -8
- data/lib/find_files.rb +99 -0
- data/lib/hash_delegator.rb +1001 -768
- data/lib/markdown_exec/version.rb +1 -1
- data/lib/mdoc.rb +27 -28
- data/lib/menu.src.yml +129 -17
- data/lib/menu.yml +94 -7
- metadata +8 -6
- data/lib/method_sorter.rb +0 -78
- data/lib/pty1.rb +0 -26
- data/lib/regexp_replacer.rb +0 -58
- data/lib/sort_yaml_gpt4.rb +0 -32
data/lib/find_files.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
#!/usr/bin/env bundle exec ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# encoding=utf-8
|
5
|
+
# version 2024-01-15
|
6
|
+
|
7
|
+
# Finds files matching a given pattern within specified directory paths.
|
8
|
+
#
|
9
|
+
# The function takes a pattern (filename or pattern with wildcards) and an array of paths.
|
10
|
+
# It searches for files matching the pattern within each of the specified paths. Hidden files
|
11
|
+
# are also included in the search. The search can include subdirectories depending on the
|
12
|
+
# path specification (e.g., 'dir/**' for recursive search).
|
13
|
+
#
|
14
|
+
# Args:
|
15
|
+
# pattern (String): A filename or a pattern string with wildcards.
|
16
|
+
# paths (Array<String>): An array of directory paths where the search will be performed.
|
17
|
+
# Paths can include wildcards for recursive search.
|
18
|
+
#
|
19
|
+
# Returns:
|
20
|
+
# Array<String>: A unique list of file paths that match the given pattern in the specified paths.
|
21
|
+
#
|
22
|
+
# Example:
|
23
|
+
# find_files('version.rb', ['lib/**', 'spec'])
|
24
|
+
# # This might return file paths like ['lib/markdown_exec/version.rb', 'spec/version_spec.rb'].
|
25
|
+
def find_files(pattern, paths)
|
26
|
+
matched_files = []
|
27
|
+
|
28
|
+
paths.each do |path_with_wildcard|
|
29
|
+
# Combine the path with the wildcard and the pattern
|
30
|
+
search_pattern = File.join(path_with_wildcard, pattern)
|
31
|
+
|
32
|
+
# Use Dir.glob with the File::FNM_DOTMATCH flag to include hidden files
|
33
|
+
matched_files += Dir.glob(search_pattern, File::FNM_DOTMATCH)
|
34
|
+
end
|
35
|
+
|
36
|
+
matched_files.uniq
|
37
|
+
end
|
38
|
+
|
39
|
+
return if $PROGRAM_NAME != __FILE__
|
40
|
+
|
41
|
+
# example CLI
|
42
|
+
# ruby lib/find_files.rb import1.md 'spec:fixtures/**:examples/**' ':'
|
43
|
+
|
44
|
+
if ARGV.length.positive?
|
45
|
+
pattern, path_list, sep = ARGV
|
46
|
+
puts find_files(pattern, path_list.split(sep || ':'))
|
47
|
+
|
48
|
+
return
|
49
|
+
end
|
50
|
+
|
51
|
+
require 'bundler/setup'
|
52
|
+
Bundler.require(:default)
|
53
|
+
|
54
|
+
require 'minitest/autorun'
|
55
|
+
|
56
|
+
class TestFindFiles < Minitest::Test
|
57
|
+
def test_find_files_no_recursion
|
58
|
+
# Test with no recursive directories
|
59
|
+
result = find_files('cli.rb', ['lib'])
|
60
|
+
assert_includes result, 'lib/cli.rb'
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_find_files_with_recursion
|
64
|
+
# Test with recursive directories
|
65
|
+
expected_files = [
|
66
|
+
'lib/cli.rb',
|
67
|
+
'lib/colorize.rb',
|
68
|
+
'lib/dev/llm.rb',
|
69
|
+
'lib/dev/watchfile.sh',
|
70
|
+
'lib/markdown_exec.rb',
|
71
|
+
'lib/markdown_exec/version.rb'
|
72
|
+
]
|
73
|
+
result = find_files('*', ['lib/**'])
|
74
|
+
expected_files.each do |file|
|
75
|
+
assert_includes result, file
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_find_files_in_multiple_paths
|
80
|
+
# Test with multiple paths
|
81
|
+
expected_files = [
|
82
|
+
'lib/markdown_exec/version.rb',
|
83
|
+
'spec/cli_spec.rb',
|
84
|
+
'spec/env_spec.rb',
|
85
|
+
'spec/markdown_exec_spec.rb',
|
86
|
+
'spec/tap_spec.rb'
|
87
|
+
]
|
88
|
+
result = find_files('*', ['lib/**', 'spec'])
|
89
|
+
expected_files.each do |file|
|
90
|
+
assert_includes result, file
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_find_files_with_hidden_files
|
95
|
+
# Test to ensure hidden files are also found
|
96
|
+
result = find_files('.gitignore', ['.'])
|
97
|
+
assert_includes result, './.gitignore'
|
98
|
+
end
|
99
|
+
end
|