grepfruit 2.0.3 → 2.0.4
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/CHANGELOG.md +3 -0
- data/README.md +93 -39
- data/exe/grepfruit +1 -1
- data/lib/grepfruit/search.rb +2 -1
- data/lib/grepfruit/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 510715dadc6ac5afba47b5a02b122eb6ae53e46dcb4454a3d83adf7374615b1e
|
4
|
+
data.tar.gz: 4797c7612d6f0ab3e0ec3c15a3c48941984f9eba4837a919ba98f10551d3c4fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a62a669cb08f455f3105ee73b4f70d991216c7b34e68477adf6546d922e43e5994ff9a9cfca38671adf69b90cb89edf1960019b8d5dd2fb3bb8df5602f6ccc2c
|
7
|
+
data.tar.gz: b85bd902107f90713cd14be4ce8662250975c76dfd95e7757a12f36da4004261098545e7929abe103c9b8204b7c457c011d129ff5daff5cc5dafa5e4aa163b34
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,97 +1,151 @@
|
|
1
|
-
# Grepfruit
|
1
|
+
# Grepfruit: File Pattern Search Tool for Ruby
|
2
2
|
|
3
3
|
[](http://badge.fury.io/rb/grepfruit)
|
4
4
|
[](https://github.com/brownboxdev/grepfruit/actions/workflows/ci.yml)
|
5
5
|
|
6
|
-
Grepfruit is a Ruby gem for searching files within a directory for
|
6
|
+
Grepfruit is a Ruby gem for searching files within a directory for specified regular expression patterns, with intelligent exclusion options and colorized output for enhanced readability. Originally designed for CI/CD pipelines to search for `TODO` comments in Ruby on Rails applications, Grepfruit provides more user-friendly output than the standard `grep` command while maintaining the flexibility for diverse search scenarios.
|
7
7
|
|
8
|
-
|
8
|
+
**Key Features:**
|
9
9
|
|
10
|
-
|
10
|
+
- Regular expression search within files and directories
|
11
|
+
- Intelligent file and directory exclusion capabilities
|
12
|
+
- Colorized output for improved readability
|
13
|
+
- Hidden file and directory search support
|
14
|
+
- Configurable output truncation
|
15
|
+
- CI/CD pipeline friendly with meaningful exit codes
|
16
|
+
- Line-specific exclusion for precise control
|
17
|
+
|
18
|
+
## Table of Contents
|
19
|
+
|
20
|
+
**Gem Usage:**
|
21
|
+
- [Installation](#installation)
|
22
|
+
- [Basic Usage](#basic-usage)
|
23
|
+
- [Command Line Options](#command-line-options)
|
24
|
+
- [Usage Examples](#usage-examples)
|
25
|
+
- [Exit Status](#exit-status)
|
26
|
+
|
27
|
+
**Community Resources:**
|
28
|
+
- [Contributing](#contributing)
|
29
|
+
- [License](#license)
|
30
|
+
- [Code of Conduct](#code-of-conduct)
|
11
31
|
|
12
32
|
## Installation
|
13
33
|
|
14
|
-
Add
|
34
|
+
Add Grepfruit to your Gemfile:
|
15
35
|
|
16
|
-
```
|
36
|
+
```rb
|
17
37
|
gem "grepfruit"
|
18
38
|
```
|
19
39
|
|
20
|
-
|
40
|
+
Install the gem:
|
21
41
|
|
22
|
-
```
|
42
|
+
```bash
|
23
43
|
bundle install
|
24
44
|
```
|
25
45
|
|
26
|
-
Or install it
|
46
|
+
Or install it directly:
|
27
47
|
|
28
|
-
```
|
48
|
+
```bash
|
29
49
|
gem install grepfruit
|
30
50
|
```
|
31
51
|
|
32
|
-
## Usage
|
52
|
+
## Basic Usage
|
33
53
|
|
34
|
-
|
54
|
+
Search for regex patterns within files in a specified directory:
|
35
55
|
|
36
|
-
```
|
56
|
+
```bash
|
37
57
|
grepfruit [options] PATH
|
38
58
|
```
|
39
59
|
|
40
|
-
If no
|
60
|
+
If no PATH is specified, Grepfruit searches the current directory.
|
61
|
+
|
62
|
+
## Command Line Options
|
63
|
+
|
64
|
+
| Option | Description |
|
65
|
+
|--------|-------------|
|
66
|
+
| `-r, --regex REGEX` | Regex pattern to search for (required) |
|
67
|
+
| `-e, --exclude x,y,z` | Comma-separated list of files, directories, or lines to exclude |
|
68
|
+
| `-t, --truncate N` | Truncate search result output to N characters |
|
69
|
+
| `--search-hidden` | Include hidden files and directories in search |
|
70
|
+
|
71
|
+
## Usage Examples
|
72
|
+
|
73
|
+
### Basic Pattern Search
|
41
74
|
|
42
|
-
|
75
|
+
Search for `TODO` comments in the current directory:
|
43
76
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
- `--search-hidden`: Search hidden files and directories.
|
77
|
+
```bash
|
78
|
+
grepfruit -r 'TODO'
|
79
|
+
```
|
48
80
|
|
49
|
-
###
|
81
|
+
### Excluding Directories
|
50
82
|
|
51
|
-
Search for
|
83
|
+
Search for `TODO` patterns while excluding common build and dependency directories:
|
52
84
|
|
53
|
-
```
|
85
|
+
```bash
|
54
86
|
grepfruit -r 'TODO' -e 'log,tmp,vendor,node_modules,assets'
|
55
87
|
```
|
56
88
|
|
57
|
-
|
89
|
+
### Multiple Pattern Search Excluding Both Directories and Files
|
90
|
+
|
91
|
+
Search for both `FIXME` and `TODO` comments in a specific directory:
|
58
92
|
|
59
|
-
```
|
93
|
+
```bash
|
60
94
|
grepfruit -r 'FIXME|TODO' -e 'bin,tmp/log,Gemfile.lock' dev/grepfruit
|
61
95
|
```
|
62
96
|
|
63
|
-
|
97
|
+
### Line-Specific Exclusion
|
64
98
|
|
65
|
-
|
99
|
+
Exclude specific lines from search results:
|
100
|
+
|
101
|
+
```bash
|
66
102
|
grepfruit -r 'FIXME|TODO' -e 'README.md:18'
|
67
103
|
```
|
68
104
|
|
69
|
-
|
105
|
+
### Output Truncation
|
106
|
+
|
107
|
+
Limit output length for cleaner results:
|
70
108
|
|
71
|
-
```
|
109
|
+
```bash
|
72
110
|
grepfruit -r 'FIXME|TODO' -t 50
|
73
111
|
```
|
74
112
|
|
75
|
-
|
113
|
+
### Including Hidden Files
|
76
114
|
|
77
|
-
|
115
|
+
Search hidden files and directories:
|
116
|
+
|
117
|
+
```bash
|
78
118
|
grepfruit -r 'FIXME|TODO' --search-hidden
|
79
119
|
```
|
80
120
|
|
81
|
-
##
|
82
|
-
|
83
|
-
Facing a problem or want to suggest an enhancement?
|
84
|
-
|
85
|
-
- **Open a Discussion**: If you have a question, experience difficulties using the gem, or have a suggestion for improvements, feel free to use the Discussions section.
|
121
|
+
## Exit Status
|
86
122
|
|
87
|
-
|
123
|
+
Grepfruit returns meaningful exit codes for CI/CD integration:
|
88
124
|
|
89
|
-
- **
|
90
|
-
- **
|
125
|
+
- **Exit code 0**: No matches found
|
126
|
+
- **Exit code 1**: Pattern matches were found
|
91
127
|
|
92
128
|
## Contributing
|
93
129
|
|
94
|
-
|
130
|
+
### Getting Help
|
131
|
+
Have a question or need assistance? Open a discussion in our [discussions section](https://github.com/brownboxdev/grepfruit/discussions) for:
|
132
|
+
- Usage questions
|
133
|
+
- Implementation guidance
|
134
|
+
- Feature suggestions
|
135
|
+
|
136
|
+
### Reporting Issues
|
137
|
+
Found a bug? Please [create an issue](https://github.com/brownboxdev/grepfruit/issues) with:
|
138
|
+
- A clear description of the problem
|
139
|
+
- Steps to reproduce the issue
|
140
|
+
- Your environment details (Ruby version, OS, etc.)
|
141
|
+
|
142
|
+
### Contributing Code
|
143
|
+
Ready to contribute? You can:
|
144
|
+
- Fix bugs by submitting pull requests
|
145
|
+
- Improve documentation
|
146
|
+
- Add new features (please discuss first in our [discussions section](https://github.com/brownboxdev/grepfruit/discussions))
|
147
|
+
|
148
|
+
Before contributing, please read the [contributing guidelines](https://github.com/brownboxdev/grepfruit/blob/master/CONTRIBUTING.md)
|
95
149
|
|
96
150
|
## License
|
97
151
|
|
data/exe/grepfruit
CHANGED
data/lib/grepfruit/search.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "pathname"
|
2
2
|
require "find"
|
3
|
+
require "byebug"
|
3
4
|
|
4
5
|
require_relative "decorator"
|
5
6
|
|
@@ -10,7 +11,7 @@ module Grepfruit
|
|
10
11
|
attr_reader :dir, :regex, :excluded_paths, :excluded_lines, :truncate, :search_hidden
|
11
12
|
|
12
13
|
def initialize(dir:, regex:, exclude:, truncate:, search_hidden:)
|
13
|
-
@dir = dir
|
14
|
+
@dir = File.expand_path(dir)
|
14
15
|
@regex = regex
|
15
16
|
@excluded_lines, @excluded_paths = exclude.map { _1.split("/") }.partition { _1.last.include?(":") }
|
16
17
|
@truncate = truncate
|
data/lib/grepfruit/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grepfruit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- enjaku4
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-05-
|
10
|
+
date: 2025-05-30 00:00:00.000000000 Z
|
11
11
|
dependencies: []
|
12
12
|
executables:
|
13
13
|
- grepfruit
|