grepfruit 0.1.0 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64111f942b9dd8e2b1b6957b552e582fc9b7870225dd40e8042de30e06832dca
4
- data.tar.gz: 40c9d6fe5cd104aa4deca5c0eadd0299851bcd286b086fd50da2ed02bbf385af
3
+ metadata.gz: 793a10b4b4676491d13d45fd598316ce327cfa660962ce37c7e3404a383f1a2e
4
+ data.tar.gz: 84f8ab7c8ff9350c95182dcc1127e7ec779b8f5a0f0f9567d845680275bda9c3
5
5
  SHA512:
6
- metadata.gz: 0bf856a22a4ab91c636e7b9ab9ae03f947b5344c9fa3266617aa4c8812e7ffd0228a84a88fa0fad9bcd10479b7b40258c85a213a160eb6d740d615111f7fbc04
7
- data.tar.gz: 6901c591fc559557064034ffce12a79c7d3f6ca8972bb00134429bed51dfab404fcc93b13b350d10acf1a281c54fe844cbbcf54a337ddb706e5dcf8af4883067
6
+ metadata.gz: d9a329e3105b5ab178180fb415ca72af96c62ab91a47d18669a3ac8514f25a5380e0d5840f457863b3f00b76766d7ddba3ca53951cfa8010e86525bca445ed41
7
+ data.tar.gz: d94287b1c4f5954920853f9303586803fb918877c7f18146528add86457b53940a4cfcda47ca63794b8caf002a7b6d02b0b3e19b6c39d5b03d5bad32b1d7e8a8
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## v1.0.0
2
+
3
+ - Removed default values for `--exclude` and `--regex` options
4
+ - Made `--regex` option required
5
+ - Fixed an error that was raised when a symbolic link was encountered during the search
6
+
7
+ ## v0.2.0
8
+
9
+ - Added `--search-hidden` option to search hidden files and directories
10
+
1
11
  ## v0.1.0
2
12
 
3
13
  - Initial release
data/README.md CHANGED
@@ -1,9 +1,14 @@
1
1
  # Grepfruit
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/grepfruit.svg)](http://badge.fury.io/rb/grepfruit)
4
+ [![Github Actions badge](https://github.com/enjaku4/grepfruit/actions/workflows/main.yml/badge.svg)](https://github.com/enjaku4/grepfruit/actions/workflows/main.yml)
5
+
3
6
  Grepfruit is a Ruby gem for searching files within a directory for a specified regular expression pattern, with options to exclude certain files or directories from the search and colorized output for better readability.
4
7
 
5
8
  <img width="416" alt="Screenshot 2024-07-28 at 03 52 37" src="https://github.com/user-attachments/assets/95b26b81-dcc1-430b-ac44-641251cb84b6">
6
9
 
10
+ Grepfruit was originally created to be used in CI/CD pipelines to search for `TODO` comments in Ruby on Rails applications and provide more user-friendly output than the standard `grep` command, but it is flexible enough to be used for other similar purposes as well.
11
+
7
12
  ## Installation
8
13
 
9
14
  Add this line to your application's Gemfile:
@@ -23,26 +28,35 @@ bundle install
23
28
  You can use Grepfruit from the command line to search for a regex pattern within files in a specified directory.
24
29
 
25
30
  ```shell
26
- grepfruit [options] PATH
31
+ bundle exec grepfruit [options] PATH
27
32
  ```
28
33
 
29
34
  ### Options
30
35
 
31
- - `-r, --regex REGEX: Regex pattern to search for. Defaults to /TODO/.
32
- - `-e, --exclude x,y,z: Comma-separated list of files and directories to exclude from the search. Defaults to log, tmp, vendor, node_modules, assets.
36
+ - `-r, --regex REGEX`: Regex pattern to search for (required).
37
+ - `-e, --exclude x,y,z`: Comma-separated list of files and directories to exclude from the search.
38
+ - `--search-hidden`: Search hidden files and directories.
33
39
 
34
40
  ### Examples
35
41
 
36
- Search for the pattern `TODO` in the current directory, excluding the default directories:
42
+ Search for the pattern `/TODO/` in the current directory, excluding `log`, `tmp`, `vendor`, `node_modules`, and `assets` directories:
43
+
44
+ ```shell
45
+ bundle exec grepfruit -r 'TODO' -e 'log,tmp,vendor,node_modules,assets'
46
+ # or
47
+ bundle exec grepfruit --regex 'TODO' --exclude 'log,tmp,vendor,node_modules,assets'
48
+ ```
49
+
50
+ Search for the pattern `/FIXME|TODO/` in `dev/grepfruit` directory, excluding `bin`, `tmp/log`, and `Gemfile.lock` files and directories:
37
51
 
38
52
  ```shell
39
- grepfruit
53
+ bundle exec grepfruit -r 'FIXME|TODO' -e 'bin,tmp/log,Gemfile.lock' dev/grepfruit
40
54
  ```
41
55
 
42
- Search for a custom pattern in another directory, while specifying files and directories to exclude:
56
+ Search for the pattern `/FIXME|TODO/` in the current directory, including hidden files and directories:
43
57
 
44
58
  ```shell
45
- grepfruit -r 'FIXME|TODO' -e 'bin,log,Rakefile,Gemfile.lock' /path/to/directory
59
+ bundle exec grepfruit -r 'FIXME|TODO' --search-hidden
46
60
  ```
47
61
 
48
62
  ## Problems?
data/exe/grepfruit CHANGED
@@ -7,22 +7,32 @@ require "grepfruit"
7
7
 
8
8
  options = {
9
9
  path: Dir.pwd,
10
- regex: /TODO/,
11
- exclude: [["log"], ["tmp"], ["vendor"], ["node_modules"], ["assets"]]
10
+ regex: nil,
11
+ exclude: [],
12
+ search_hidden: false
12
13
  }
13
14
 
14
15
  OptionParser.new do |opts|
15
16
  opts.banner = "Usage: grepfruit [options] PATH"
16
17
 
17
- opts.on("-r", "--regex REGEX", "Regex pattern to search for") do |regex|
18
- options[:regex] = /#{regex}/
18
+ opts.on("-r", "--regex REGEX", Regexp, "Regex pattern to search for") do |regex|
19
+ options[:regex] = regex
19
20
  end
20
21
 
21
22
  opts.on("-e", "--exclude x,y,z", Array, "Comma-separated list of files and directories to exclude") do |exclude|
22
23
  options[:exclude] = exclude.map! { |path| path.split("/") }
23
24
  end
25
+
26
+ opts.on("--search-hidden", TrueClass, "Search hidden files and directories") do |search_hidden|
27
+ options[:search_hidden] = search_hidden
28
+ end
24
29
  end.parse!
25
30
 
31
+ if options[:regex].nil?
32
+ puts "Error: You must specify a regex pattern using the -r or --regex option."
33
+ exit 1
34
+ end
35
+
26
36
  options[:path] = ARGV[0] if ARGV[0]
27
37
 
28
38
  Grepfruit.run(**options)
@@ -1,3 +1,3 @@
1
1
  module Grepfruit
2
- VERSION = "0.1.0"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/grepfruit.rb CHANGED
@@ -3,7 +3,7 @@ require "pathname"
3
3
  require "find"
4
4
 
5
5
  module Grepfruit
6
- def self.run(path:, regex:, exclude:)
6
+ def self.run(path:, regex:, exclude:, search_hidden:)
7
7
  lines = []
8
8
  files = 0
9
9
  dir = path
@@ -11,9 +11,9 @@ module Grepfruit
11
11
  puts "Searching for #{regex.inspect}...\n\n"
12
12
 
13
13
  Find.find(dir) do |pth|
14
- Find.prune if exclude.any? { |e| pth.split("/").last(e.length) == e } || File.basename(pth).start_with?(".")
14
+ Find.prune if exclude.any? { |e| pth.split("/").last(e.length) == e } || !search_hidden && File.basename(pth).start_with?(".")
15
15
 
16
- next if File.directory?(pth)
16
+ next if File.directory?(pth) || File.symlink?(pth)
17
17
 
18
18
  files += 1
19
19
 
@@ -34,7 +34,7 @@ module Grepfruit
34
34
  puts "\n\n"
35
35
 
36
36
  if lines.empty?
37
- puts "#{files} files checked, \e[32mno matches found\e[0m"
37
+ puts "#{files} file#{'s' if files > 1} checked, \e[32mno matches found\e[0m"
38
38
  exit(0)
39
39
  else
40
40
  puts "Matches:\n\n"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grepfruit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - enjaku4
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-28 00:00:00.000000000 Z
11
+ date: 2024-07-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -47,7 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0'
49
49
  requirements: []
50
- rubygems_version: 3.2.33
50
+ rubygems_version: 3.5.11
51
51
  signing_key:
52
52
  specification_version: 4
53
53
  summary: A tool for searching text patterns in files with colorized output.