find-cli 1.5.0 → 1.6.3
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 +41 -0
- package/bin/abbreviations.js +6 -2
- package/bin/action/find.js +4 -1
- package/bin/action/help.js +8 -0
- package/bin/defaults.js +8 -2
- package/bin/isIgnored/asynchronous.js +5 -5
- package/bin/main.js +21 -7
- package/bin/operation/find.js +4 -0
- package/bin/operation/prompt/pathRule.js +51 -0
- package/bin/operation/prompt/rule.js +20 -5
- package/bin/operation/rule.js +9 -1
- package/bin/operation/updatePatRules.js +9 -9
- package/bin/options.js +10 -2
- package/bin/utilities/validate.js +1 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -58,6 +58,14 @@ Options:
|
|
|
58
58
|
--quietly|-q Do not show the directory and file path matching
|
|
59
59
|
|
|
60
60
|
--format|-f Formatted output, shown only once the search completes.
|
|
61
|
+
|
|
62
|
+
--glob|-g Treat the argument as a glob, which is the default.
|
|
63
|
+
|
|
64
|
+
--regex|-g Treat the argument as a regular expression.
|
|
65
|
+
|
|
66
|
+
--string|-s Treat the argument as a string.
|
|
67
|
+
|
|
68
|
+
--interactive|-i Interactive mode, allowing the argument to be provided via stdin.
|
|
61
69
|
```
|
|
62
70
|
|
|
63
71
|
### Setup
|
|
@@ -147,6 +155,39 @@ Here is a list of some of the conversions:
|
|
|
147
155
|
Character classes and alternatives are also supported.
|
|
148
156
|
Their conversions are more or less standard.
|
|
149
157
|
|
|
158
|
+
### Command line considerations
|
|
159
|
+
|
|
160
|
+
Node is only supplied with the parsed command string and since shells remove double quotes, the following...
|
|
161
|
+
|
|
162
|
+
find -q "START_OF_CONTENT"
|
|
163
|
+
|
|
164
|
+
...may as well be:
|
|
165
|
+
|
|
166
|
+
find -q START_OF_CONTENT
|
|
167
|
+
|
|
168
|
+
In either case the argument will be treated as a glob because Find does not see any double quotes.
|
|
169
|
+
|
|
170
|
+
There are two ways around this.
|
|
171
|
+
|
|
172
|
+
1. You can use the interactive mode:
|
|
173
|
+
|
|
174
|
+
```
|
|
175
|
+
find -qi
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
This will allow you to input `"START_OF_CONTENT"` by hand, so to speak. Since Node is now reading `stdin` rather than a parsed command string, the quotes will remain.
|
|
179
|
+
|
|
180
|
+
2. Use the `-s` flag:
|
|
181
|
+
|
|
182
|
+
```
|
|
183
|
+
find -qs START_OF_CONTENT
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
This coerces Find into treating the argument as a string irregardless of the missing double quotes.
|
|
187
|
+
|
|
188
|
+
There is also the `-r` flag for regular expressions if you do not want to type the `/` regular expression delimiters, by the way.
|
|
189
|
+
And lastly, the `-g` flag for globs is provided for the sake of completeness but since globs are the default it is never really needed.
|
|
190
|
+
|
|
150
191
|
## Contact
|
|
151
192
|
|
|
152
193
|
* james.smith@djalbat.com
|
package/bin/abbreviations.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const { HELP_OPTION, FORMAT_OPTION, VERSION_OPTION, DRY_RUN_OPTION, QUIETLY_OPTION } = require("./options");
|
|
3
|
+
const { HELP_OPTION, GLOB_OPTION, REGEX_OPTION, STRING_OPTION, FORMAT_OPTION, VERSION_OPTION, DRY_RUN_OPTION, QUIETLY_OPTION, INTERACTIVE_OPTION } = require("./options");
|
|
4
4
|
|
|
5
5
|
module.exports = {
|
|
6
6
|
"h": HELP_OPTION,
|
|
7
|
+
"g": GLOB_OPTION,
|
|
8
|
+
"r": REGEX_OPTION,
|
|
9
|
+
"s": STRING_OPTION,
|
|
7
10
|
"f": FORMAT_OPTION,
|
|
8
11
|
"v": VERSION_OPTION,
|
|
9
12
|
"d": DRY_RUN_OPTION,
|
|
10
|
-
"q": QUIETLY_OPTION
|
|
13
|
+
"q": QUIETLY_OPTION,
|
|
14
|
+
"i": INTERACTIVE_OPTION
|
|
11
15
|
};
|
package/bin/action/find.js
CHANGED
|
@@ -2,14 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
const ruleOperation = require("../operation/rule"),
|
|
4
4
|
findOperation = require("../operation/find"),
|
|
5
|
+
rulePromptOperation = require("../operation/prompt/rule"),
|
|
5
6
|
readConfigurationOperation = require("../operation/readConfiguration");
|
|
6
7
|
|
|
7
8
|
const { S, EMPTY_STRING } = require("../constants"),
|
|
8
9
|
{ executeOperations } = require("../utilities/operation");
|
|
9
10
|
|
|
10
|
-
function findAction(string, dryRun, format, quietly) {
|
|
11
|
+
function findAction(string, dryRun, format, quietly, interactive) {
|
|
11
12
|
const operations = [
|
|
12
13
|
ruleOperation,
|
|
14
|
+
rulePromptOperation,
|
|
13
15
|
readConfigurationOperation,
|
|
14
16
|
findOperation
|
|
15
17
|
],
|
|
@@ -24,6 +26,7 @@ function findAction(string, dryRun, format, quietly) {
|
|
|
24
26
|
dryRun,
|
|
25
27
|
format,
|
|
26
28
|
quietly,
|
|
29
|
+
interactive,
|
|
27
30
|
rule,
|
|
28
31
|
lines,
|
|
29
32
|
linesTotal,
|
package/bin/action/help.js
CHANGED
|
@@ -31,6 +31,14 @@ Options:
|
|
|
31
31
|
|
|
32
32
|
--format|-f Formatted output, shown only once the search completes.
|
|
33
33
|
|
|
34
|
+
--glob|-g Treat the argument as a glob, which is the default.
|
|
35
|
+
|
|
36
|
+
--regex|-g Treat the argument as a regular expression.
|
|
37
|
+
|
|
38
|
+
--string|-s Treat the argument as a string.
|
|
39
|
+
|
|
40
|
+
--interactive|-i Interactive mode, allowing the argument to be provided via stdin.
|
|
41
|
+
|
|
34
42
|
Further information:
|
|
35
43
|
|
|
36
44
|
Please see the readme file on GitHub:
|
package/bin/defaults.js
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const DEFAULT_HELP = false,
|
|
4
|
+
DEFAULT_REGEX = false,
|
|
5
|
+
DEFAULT_STRING = false,
|
|
4
6
|
DEFAULT_FORMAT = false,
|
|
5
7
|
DEFAULT_VERSION = false,
|
|
6
8
|
DEFAULT_DRY_RUN = false,
|
|
7
|
-
DEFAULT_QUIETLY = false
|
|
9
|
+
DEFAULT_QUIETLY = false,
|
|
10
|
+
DEFAULT_INTERACTIVE = false;
|
|
8
11
|
|
|
9
12
|
module.exports = {
|
|
10
13
|
DEFAULT_HELP,
|
|
14
|
+
DEFAULT_REGEX,
|
|
15
|
+
DEFAULT_STRING,
|
|
11
16
|
DEFAULT_FORMAT,
|
|
12
17
|
DEFAULT_VERSION,
|
|
13
18
|
DEFAULT_DRY_RUN,
|
|
14
|
-
DEFAULT_QUIETLY
|
|
19
|
+
DEFAULT_QUIETLY,
|
|
20
|
+
DEFAULT_INTERACTIVE
|
|
15
21
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const pathRulePromptOperation = require("../operation/prompt/pathRule"),
|
|
4
4
|
updatePathRulesOperation = require("../operation/updatePatRules"),
|
|
5
5
|
ignoreOrPermitPathPromptOperation = require("../operation/prompt/ignoreOrPermitPath");
|
|
6
6
|
|
|
@@ -33,25 +33,25 @@ module.exports = {
|
|
|
33
33
|
function asynchronousIsPathIgnored(path, directory, context, callback) {
|
|
34
34
|
const operations = [
|
|
35
35
|
ignoreOrPermitPathPromptOperation,
|
|
36
|
-
|
|
36
|
+
pathRulePromptOperation,
|
|
37
37
|
updatePathRulesOperation
|
|
38
38
|
],
|
|
39
|
-
|
|
39
|
+
pathRule = null,
|
|
40
40
|
pathIgnored = null;
|
|
41
41
|
|
|
42
42
|
Object.assign(context, {
|
|
43
|
-
rule,
|
|
44
43
|
path,
|
|
45
44
|
directory,
|
|
45
|
+
pathRule,
|
|
46
46
|
pathIgnored
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
executeOperations(operations, (completed) => {
|
|
50
50
|
const { pathIgnored } = context;
|
|
51
51
|
|
|
52
|
-
delete context.rule;
|
|
53
52
|
delete context.path;
|
|
54
53
|
delete context.directory;
|
|
54
|
+
delete context.pathRule;
|
|
55
55
|
delete context.pathIgnored;
|
|
56
56
|
|
|
57
57
|
callback(pathIgnored);
|
package/bin/main.js
CHANGED
|
@@ -9,7 +9,7 @@ const findAction = require("./action/find"),
|
|
|
9
9
|
removeRootDirectoryPathAction = require("./action/removeRootDirectoryPath");
|
|
10
10
|
|
|
11
11
|
const { NO_ARGUMENT_GIVEN_MESSAGE, COMMAND_NOT_RECOGNISED_MESSAGE } = require("./messages"),
|
|
12
|
-
{ DEFAULT_FORMAT, DEFAULT_DRY_RUN, DEFAULT_QUIETLY } = require("./defaults"),
|
|
12
|
+
{ DEFAULT_REGEX, DEFAULT_STRING, DEFAULT_FORMAT, DEFAULT_DRY_RUN, DEFAULT_QUIETLY, DEFAULT_INTERACTIVE } = require("./defaults"),
|
|
13
13
|
{ FIND_COMMAND,
|
|
14
14
|
HELP_COMMAND,
|
|
15
15
|
VERSION_COMMAND,
|
|
@@ -19,7 +19,9 @@ const { NO_ARGUMENT_GIVEN_MESSAGE, COMMAND_NOT_RECOGNISED_MESSAGE } = require(".
|
|
|
19
19
|
REMOVE_ROOT_DIRECTORY_PATH_COMMAND } = require("./commands");
|
|
20
20
|
|
|
21
21
|
function main(command, argument, options) {
|
|
22
|
-
const { format = DEFAULT_FORMAT, dryRun = DEFAULT_DRY_RUN, quietly = DEFAULT_QUIETLY } = options;
|
|
22
|
+
const { format = DEFAULT_FORMAT, dryRun = DEFAULT_DRY_RUN, quietly = DEFAULT_QUIETLY, interactive = DEFAULT_INTERACTIVE } = options;
|
|
23
|
+
|
|
24
|
+
let { regex = DEFAULT_REGEX, string = DEFAULT_STRING } = options;
|
|
23
25
|
|
|
24
26
|
switch (command) {
|
|
25
27
|
case HELP_COMMAND: {
|
|
@@ -63,14 +65,26 @@ function main(command, argument, options) {
|
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
case FIND_COMMAND: {
|
|
66
|
-
if (
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
if (argument === null) {
|
|
69
|
+
if (!dryRun && !interactive) {
|
|
70
|
+
console.log(NO_ARGUMENT_GIVEN_MESSAGE);
|
|
71
|
+
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
70
75
|
|
|
71
|
-
|
|
76
|
+
if (false) {
|
|
77
|
+
///
|
|
78
|
+
} else if (string) {
|
|
79
|
+
argument = `"${argument}"`;
|
|
80
|
+
} else if (regex) {
|
|
81
|
+
argument = `/${argument}/`;
|
|
72
82
|
}
|
|
73
83
|
|
|
84
|
+
string = argument; ///
|
|
85
|
+
|
|
86
|
+
findAction(string, dryRun, format, quietly, interactive);
|
|
87
|
+
|
|
74
88
|
break;
|
|
75
89
|
}
|
|
76
90
|
|
package/bin/operation/find.js
CHANGED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { shellUtilities } = require("necessary");
|
|
4
|
+
|
|
5
|
+
const { validateGlobStringOrPattern } = require("../../utilities/validate"),
|
|
6
|
+
{ GLOB_STRING_OR_REGEX_DESCRIPTION } = require("../../descriptions"),
|
|
7
|
+
{ ruleFromStringAnchoredAndDirectory } = require("../../utilities/rule"),
|
|
8
|
+
{ INVALID_GLOB_REGEX_OR_STRING_MESSAGE } = require("../../messages");
|
|
9
|
+
|
|
10
|
+
const { prompt } = shellUtilities;
|
|
11
|
+
|
|
12
|
+
function pathRulePromptOperation(proceed, abort, context) {
|
|
13
|
+
const { path, directory } = context,
|
|
14
|
+
anchored = true,
|
|
15
|
+
description = GLOB_STRING_OR_REGEX_DESCRIPTION,
|
|
16
|
+
errorMessage = INVALID_GLOB_REGEX_OR_STRING_MESSAGE,
|
|
17
|
+
initialAnswer = path, ///
|
|
18
|
+
validationFunction = (answer) => {
|
|
19
|
+
const valid = validateGlobStringOrPattern(answer, anchored, directory);
|
|
20
|
+
|
|
21
|
+
return valid;
|
|
22
|
+
},
|
|
23
|
+
options = {
|
|
24
|
+
description,
|
|
25
|
+
errorMessage,
|
|
26
|
+
initialAnswer,
|
|
27
|
+
validationFunction
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
prompt(options, (answer) => {
|
|
31
|
+
const valid = (answer !== null);
|
|
32
|
+
|
|
33
|
+
if(!valid) {
|
|
34
|
+
abort();
|
|
35
|
+
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const string = answer, ///
|
|
40
|
+
rule = ruleFromStringAnchoredAndDirectory(string, anchored, directory),
|
|
41
|
+
pathRule = rule; ///
|
|
42
|
+
|
|
43
|
+
Object.assign(context, {
|
|
44
|
+
pathRule
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
proceed();
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
module.exports = pathRulePromptOperation;
|
|
@@ -2,20 +2,36 @@
|
|
|
2
2
|
|
|
3
3
|
const { shellUtilities } = require("necessary");
|
|
4
4
|
|
|
5
|
-
const {
|
|
6
|
-
{ validateGlobStringOrPattern } = require("../../utilities/validate"),
|
|
5
|
+
const { validateGlobStringOrPattern } = require("../../utilities/validate"),
|
|
7
6
|
{ GLOB_STRING_OR_REGEX_DESCRIPTION } = require("../../descriptions"),
|
|
7
|
+
{ ruleFromStringAnchoredAndDirectory } = require("../../utilities/rule"),
|
|
8
8
|
{ INVALID_GLOB_REGEX_OR_STRING_MESSAGE } = require("../../messages");
|
|
9
9
|
|
|
10
10
|
const { prompt } = shellUtilities;
|
|
11
11
|
|
|
12
12
|
function rulePromptOperation(proceed, abort, context) {
|
|
13
|
-
const {
|
|
13
|
+
const { dryRun } = context;
|
|
14
|
+
|
|
15
|
+
if (dryRun) {
|
|
16
|
+
proceed();
|
|
17
|
+
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const { interactive } = context;
|
|
22
|
+
|
|
23
|
+
if (!interactive) {
|
|
24
|
+
proceed();
|
|
25
|
+
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const { path, anchored, directory } = context,
|
|
14
30
|
description = GLOB_STRING_OR_REGEX_DESCRIPTION,
|
|
15
31
|
errorMessage = INVALID_GLOB_REGEX_OR_STRING_MESSAGE,
|
|
16
32
|
initialAnswer = path, ///
|
|
17
33
|
validationFunction = (answer) => {
|
|
18
|
-
const valid = validateGlobStringOrPattern(answer, directory);
|
|
34
|
+
const valid = validateGlobStringOrPattern(answer, anchored, directory);
|
|
19
35
|
|
|
20
36
|
return valid;
|
|
21
37
|
},
|
|
@@ -36,7 +52,6 @@ function rulePromptOperation(proceed, abort, context) {
|
|
|
36
52
|
}
|
|
37
53
|
|
|
38
54
|
const string = answer, ///
|
|
39
|
-
anchored = true,
|
|
40
55
|
rule = ruleFromStringAnchoredAndDirectory(string, anchored, directory);
|
|
41
56
|
|
|
42
57
|
Object.assign(context, {
|
package/bin/operation/rule.js
CHANGED
|
@@ -11,9 +11,17 @@ function ruleOperation(proceed, abort, context) {
|
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
const { interactive } = context;
|
|
15
|
+
|
|
16
|
+
if (interactive) {
|
|
17
|
+
proceed();
|
|
18
|
+
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
14
22
|
const { string } = context,
|
|
23
|
+
anchored = true,
|
|
15
24
|
directory = false,
|
|
16
|
-
anchored = false,
|
|
17
25
|
rule = ruleFromStringAnchoredAndDirectory(string, anchored, directory);
|
|
18
26
|
|
|
19
27
|
if (rule === null) {
|
|
@@ -6,28 +6,28 @@ const { updateIgnoredFilePathRules,
|
|
|
6
6
|
updatePermittedDirectoryPathRules } = require("../configuration");
|
|
7
7
|
|
|
8
8
|
function updatePathRulesOperation(proceed, abort, context) {
|
|
9
|
-
const {
|
|
9
|
+
const { pathRule, directory, pathIgnored } = context;
|
|
10
10
|
|
|
11
11
|
pathIgnored ?
|
|
12
|
-
addIgnoreRule(
|
|
13
|
-
addPermitRule(
|
|
12
|
+
addIgnoreRule(pathRule, directory, context) :
|
|
13
|
+
addPermitRule(pathRule, directory, context);
|
|
14
14
|
|
|
15
15
|
proceed();
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
module.exports = updatePathRulesOperation;
|
|
19
19
|
|
|
20
|
-
function addIgnoreRule(
|
|
20
|
+
function addIgnoreRule(pathRule, directory, context) {
|
|
21
21
|
if (directory) {
|
|
22
22
|
const { ignoredDirectoryPathRules } = context,
|
|
23
|
-
ignoredDirectoryPathRule =
|
|
23
|
+
ignoredDirectoryPathRule = pathRule; ///
|
|
24
24
|
|
|
25
25
|
ignoredDirectoryPathRules.push(ignoredDirectoryPathRule);
|
|
26
26
|
|
|
27
27
|
updateIgnoredDirectoryPathRules(ignoredDirectoryPathRules);
|
|
28
28
|
} else {
|
|
29
29
|
const { ignoredFilePathRules } = context,
|
|
30
|
-
ignoredFilePathRule =
|
|
30
|
+
ignoredFilePathRule = pathRule; ///
|
|
31
31
|
|
|
32
32
|
ignoredFilePathRules.push(ignoredFilePathRule);
|
|
33
33
|
|
|
@@ -35,17 +35,17 @@ function addIgnoreRule(rule, directory, context) {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
function addPermitRule(
|
|
38
|
+
function addPermitRule(pathRule, directory, context) {
|
|
39
39
|
if (directory) {
|
|
40
40
|
const { permittedDirectoryPathRules } = context,
|
|
41
|
-
permittedDirectoryPathRule =
|
|
41
|
+
permittedDirectoryPathRule = pathRule; ///
|
|
42
42
|
|
|
43
43
|
permittedDirectoryPathRules.push(permittedDirectoryPathRule);
|
|
44
44
|
|
|
45
45
|
updatePermittedDirectoryPathRules(permittedDirectoryPathRules);
|
|
46
46
|
} else {
|
|
47
47
|
const { permittedFilePathRules } = context,
|
|
48
|
-
permittedFilePathRule =
|
|
48
|
+
permittedFilePathRule = pathRule; ///
|
|
49
49
|
|
|
50
50
|
permittedFilePathRules.push(permittedFilePathRule);
|
|
51
51
|
|
package/bin/options.js
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const HELP_OPTION = "help",
|
|
4
|
+
GLOB_OPTION = "glob",
|
|
5
|
+
REGEX_OPTION = "regex",
|
|
6
|
+
STRING_OPTION = "string",
|
|
4
7
|
FORMAT_OPTION = "format",
|
|
5
8
|
VERSION_OPTION = "version",
|
|
6
9
|
QUIETLY_OPTION = "quietly",
|
|
7
|
-
DRY_RUN_OPTION = "dry-run"
|
|
10
|
+
DRY_RUN_OPTION = "dry-run",
|
|
11
|
+
INTERACTIVE_OPTION = "interactive";
|
|
8
12
|
|
|
9
13
|
module.exports = {
|
|
10
14
|
HELP_OPTION,
|
|
15
|
+
GLOB_OPTION,
|
|
16
|
+
REGEX_OPTION,
|
|
17
|
+
STRING_OPTION,
|
|
11
18
|
FORMAT_OPTION,
|
|
12
19
|
VERSION_OPTION,
|
|
13
20
|
QUIETLY_OPTION,
|
|
14
|
-
DRY_RUN_OPTION
|
|
21
|
+
DRY_RUN_OPTION,
|
|
22
|
+
INTERACTIVE_OPTION
|
|
15
23
|
};
|
|
@@ -39,9 +39,8 @@ function validateRootDirectoryPath(answer) {
|
|
|
39
39
|
return valid;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
function validateGlobStringOrPattern(answer, directory) {
|
|
42
|
+
function validateGlobStringOrPattern(answer, anchored, directory) {
|
|
43
43
|
const string = answer, ///
|
|
44
|
-
anchored = false,
|
|
45
44
|
rule = ruleFromStringAnchoredAndDirectory(string, anchored, directory),
|
|
46
45
|
valid = (rule !== null)
|
|
47
46
|
|