find-cli 1.4.7 → 1.4.10
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.
- package/README.md +95 -4
- package/bin/action/find.js +3 -8
- package/bin/action/help.js +2 -2
- package/bin/messages.js +0 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
# Find-CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An alternative to `grep`.
|
|
4
|
+
|
|
5
|
+
Find looks for occurrences in files' contents that match a supplied glob, string or regular expression.
|
|
6
|
+
It filters files and directories by way of configurable path matching rules that are also based on globs, strings and regular expressions.
|
|
7
|
+
It is quite like `grep` but it is arguably more user friendly and surprisingly just as fast.
|
|
8
|
+
|
|
9
|
+
Find uses globs by default for matching both content and paths.
|
|
10
|
+
Its use of them is slightly non-standard but hopefully de-mystifying.
|
|
11
|
+
In fact there is is a section below devoted to how they are converted to regular expressions.
|
|
4
12
|
|
|
5
13
|
## Installation
|
|
6
14
|
|
|
@@ -45,15 +53,98 @@ Options:
|
|
|
45
53
|
|
|
46
54
|
--version|-v Show the version
|
|
47
55
|
|
|
48
|
-
--dry-run|-d Traverse the directories and files
|
|
56
|
+
--dry-run|-d Traverse the directories and files only
|
|
49
57
|
|
|
50
|
-
--quietly|-q
|
|
58
|
+
--quietly|-q Do not show the directory and file path matching
|
|
51
59
|
```
|
|
52
60
|
|
|
53
|
-
|
|
61
|
+
### Setup
|
|
54
62
|
|
|
63
|
+
Suppose that you want to search your `~/Development` directory.
|
|
64
|
+
First run the following commands:
|
|
65
|
+
|
|
66
|
+
cd ~/Development
|
|
55
67
|
find initialise
|
|
56
68
|
|
|
69
|
+
This creates a `.findrc` configuration file in the `~/Development` directory that under normal circumstances should not be edited by hand.
|
|
70
|
+
|
|
71
|
+
Now suppose that you also want to search a sibling `~/Sites` directory.
|
|
72
|
+
You can configure this additional root directory and see the results with the following commands:
|
|
73
|
+
|
|
74
|
+
find add-root-directory ../Sites/
|
|
75
|
+
find list-root-directories
|
|
76
|
+
|
|
77
|
+
### Path rules
|
|
78
|
+
|
|
79
|
+
Once you have the root directories set up you can start to add the rules that filter the file and directory paths.
|
|
80
|
+
Start with a dry run so that there is no need to specify what to search for:
|
|
81
|
+
|
|
82
|
+
find -d
|
|
83
|
+
|
|
84
|
+
Find works from four collections of rules for ignoring and permitting file and directory paths.
|
|
85
|
+
It ignores paths first but can subsequently permit them.
|
|
86
|
+
It must be able to match a rule to each path that it encounters.
|
|
87
|
+
If not it will prompt you to configure one.
|
|
88
|
+
For example, the very first file that it encounters may be its own `.findrc` configuration file.
|
|
89
|
+
In that case it will ask you whether you want to ignore or permit that path and then prompt you for a glob, string or regular expression to match the path as a whole.
|
|
90
|
+
The choice is yours but globs are the default and do not have delimiters.
|
|
91
|
+
|
|
92
|
+
.findrc // gllob
|
|
93
|
+
".findrc" // string
|
|
94
|
+
/\.findrc/ // regular expression
|
|
95
|
+
|
|
96
|
+
You may have several thousand files and directories that need matching and wildcards will obviously be needed.
|
|
97
|
+
It can take several minutes to answer all the prompts but you can opt out at any time by hitting the enter key three times at any prompt.
|
|
98
|
+
A little patience with the process and a couple of tries at it are recommended.
|
|
99
|
+
|
|
100
|
+
Once the rules are set up there is little more to do other than to search for occurrences, again using globs, strings or regular expressions.
|
|
101
|
+
For example:
|
|
102
|
+
|
|
103
|
+
find -q START_OF_CONTENT
|
|
104
|
+
find -q "Query.fromExpression"
|
|
105
|
+
find -q /"[^"]*"/
|
|
106
|
+
|
|
107
|
+
The `-q` flag here suppresses the path matching messages.
|
|
108
|
+
Only the occurrences will be shown once the search is complete.
|
|
109
|
+
|
|
110
|
+
### Converting globs to regular expressions
|
|
111
|
+
|
|
112
|
+
Find differentiates between directory and file paths and this is important when converting globs.
|
|
113
|
+
Directory paths *must* end with a slash.
|
|
114
|
+
So:
|
|
115
|
+
|
|
116
|
+
/ // root directory
|
|
117
|
+
./ // current directory
|
|
118
|
+
../ // parent directory
|
|
119
|
+
foo/
|
|
120
|
+
foo/bar/
|
|
121
|
+
|
|
122
|
+
Find will add the trailing slashes when matching directory paths.
|
|
123
|
+
For example:
|
|
124
|
+
|
|
125
|
+
Ignore ../Sites/account.xomi.cloud/template/ */template/**/
|
|
126
|
+
|
|
127
|
+
Note that the root directory has been prepended, but only for clarity when showing messages.
|
|
128
|
+
It is not prepended for the purpose of matching.
|
|
129
|
+
A trailing slash has been prepended, however, and this has a bearing on how the glob is converted.
|
|
130
|
+
|
|
131
|
+
One thing to note is that you do not have to remember to prepend trailing slashes yourself when prompted for globs, strings or regular expressions ot match directory paths.
|
|
132
|
+
Find will always add them.
|
|
133
|
+
|
|
134
|
+
Although non-standard, The presence of a trailing slash for directory paths means makes the conversion of globs to regular expressions easier.
|
|
135
|
+
Here is a list of some of the conversions:
|
|
136
|
+
|
|
137
|
+
| Glob | Regular expression | Description |
|
|
138
|
+
|-------|--------------------|----------------------|
|
|
139
|
+
| `**/` | `(?:[^/]*\\/)*` | Repeated directories |
|
|
140
|
+
| `*/` | `[^/]*\\/` | Single directory |
|
|
141
|
+
| `/` | `\\/` | Directory |
|
|
142
|
+
| `**` | `.*` | Repeated wildcard |
|
|
143
|
+
| `*` | `.+?` | Single wildcard |
|
|
144
|
+
|
|
145
|
+
Character classes and alternatives are also supported.
|
|
146
|
+
Their conversions are more or less standard.
|
|
147
|
+
|
|
57
148
|
## Contact
|
|
58
149
|
|
|
59
150
|
* james.smith@djalbat.com
|
package/bin/action/find.js
CHANGED
|
@@ -5,8 +5,7 @@ const ruleOperation = require("../operation/rule"),
|
|
|
5
5
|
readConfigurationOperation = require("../operation/readConfiguration");
|
|
6
6
|
|
|
7
7
|
const { S, EMPTY_STRING } = require("../constants"),
|
|
8
|
-
{ executeOperations } = require("../utilities/operation")
|
|
9
|
-
{ FAILED_FIND_MESSAGE, SUCCESSFUL_FIND_MESSAGE } = require("../messages");
|
|
8
|
+
{ executeOperations } = require("../utilities/operation");
|
|
10
9
|
|
|
11
10
|
function findAction(string, dryRun, quietly) {
|
|
12
11
|
const operations = [
|
|
@@ -33,17 +32,13 @@ function findAction(string, dryRun, quietly) {
|
|
|
33
32
|
};
|
|
34
33
|
|
|
35
34
|
executeOperations(operations, (completed) => {
|
|
36
|
-
|
|
35
|
+
logLines(context);
|
|
37
36
|
|
|
38
37
|
if (!completed) {
|
|
39
|
-
console.log(FAILED_FIND_MESSAGE);
|
|
40
|
-
|
|
41
38
|
return;
|
|
42
39
|
}
|
|
43
40
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
console.log(SUCCESSFUL_FIND_MESSAGE);
|
|
41
|
+
logTottals(context);
|
|
47
42
|
}, context);
|
|
48
43
|
}
|
|
49
44
|
|
package/bin/action/help.js
CHANGED
|
@@ -25,9 +25,9 @@ Options:
|
|
|
25
25
|
|
|
26
26
|
--version|-v Show the version
|
|
27
27
|
|
|
28
|
-
--dry-run|-d Traverse the directories and files
|
|
28
|
+
--dry-run|-d Traverse the directories and files only
|
|
29
29
|
|
|
30
|
-
--quietly|-q
|
|
30
|
+
--quietly|-q Do not show the directory and file path matching
|
|
31
31
|
|
|
32
32
|
Further information:
|
|
33
33
|
|
package/bin/messages.js
CHANGED
|
@@ -8,11 +8,9 @@ const NO_ARGUMENT_GIVEN_MESSAGE = "No argument has been given.",
|
|
|
8
8
|
INVALID_ROOT_DIRECTORY_PATH_MESSAGE = "Additional root directories must be globs of the form '../**/'.",
|
|
9
9
|
INVALID_GLOB_REGEX_OR_STRING_MESSAGE = "The glob, regex or string is invalid.",
|
|
10
10
|
INVALID_ROOT_DIRECTORY_PATH_INDEX_MESSAGE = "The index is either not a number or not within range.",
|
|
11
|
-
FAILED_FIND_MESSAGE = "Failed to search everything.",
|
|
12
11
|
FAILED_INITIALISE_MESSAGE = "Failed to create a configuration file because one is already present.",
|
|
13
12
|
FAILED_ADD_ROOT_DIRECTORY_MESSAGE = "Failed to add the root directory.",
|
|
14
13
|
FAILED_REMOVE_ROOT_DIRECTORY_MESSAGE = "Failed to remove the root directory.",
|
|
15
|
-
SUCCESSFUL_FIND_MESSAGE = "Searched everything successfully.",
|
|
16
14
|
SUCCESSFUL_INITIALISE_MESSAGE = "The configuration file has been created successfully.",
|
|
17
15
|
SUCCESSFUL_ADD_ROOT_DIRECTORY_MESSAGE = "Added the root directory successfully.",
|
|
18
16
|
SUCCESSFUL_REMOVE_ROOT_DIRECTORY_MESSAGE = "Removed the root directory successfully.";
|
|
@@ -26,11 +24,9 @@ module.exports = {
|
|
|
26
24
|
INVALID_ROOT_DIRECTORY_PATH_MESSAGE,
|
|
27
25
|
INVALID_GLOB_REGEX_OR_STRING_MESSAGE,
|
|
28
26
|
INVALID_ROOT_DIRECTORY_PATH_INDEX_MESSAGE,
|
|
29
|
-
FAILED_FIND_MESSAGE,
|
|
30
27
|
FAILED_INITIALISE_MESSAGE,
|
|
31
28
|
FAILED_ADD_ROOT_DIRECTORY_MESSAGE,
|
|
32
29
|
FAILED_REMOVE_ROOT_DIRECTORY_MESSAGE,
|
|
33
|
-
SUCCESSFUL_FIND_MESSAGE,
|
|
34
30
|
SUCCESSFUL_INITIALISE_MESSAGE,
|
|
35
31
|
SUCCESSFUL_ADD_ROOT_DIRECTORY_MESSAGE,
|
|
36
32
|
SUCCESSFUL_REMOVE_ROOT_DIRECTORY_MESSAGE
|