find-cli 1.5.0 → 1.6.2

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 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
@@ -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
  };
@@ -2,19 +2,23 @@
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
  ],
16
18
  rule = null,
17
19
  lines = [],
20
+ anchored = false,
21
+ directory = false,
18
22
  linesTotal = 0,
19
23
  filesTotal = 0,
20
24
  directoriesTotal = 0,
@@ -24,8 +28,11 @@ function findAction(string, dryRun, format, quietly) {
24
28
  dryRun,
25
29
  format,
26
30
  quietly,
31
+ interactive,
27
32
  rule,
28
33
  lines,
34
+ anchored,
35
+ directory,
29
36
  linesTotal,
30
37
  filesTotal,
31
38
  directoriesTotal,
@@ -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
  };
@@ -37,12 +37,18 @@ function asynchronousIsPathIgnored(path, directory, context, callback) {
37
37
  updatePathRulesOperation
38
38
  ],
39
39
  rule = null,
40
+ dryRun = false,
41
+ anchored = true,
42
+ interactive = true,
40
43
  pathIgnored = null;
41
44
 
42
45
  Object.assign(context, {
43
- rule,
44
46
  path,
45
47
  directory,
48
+ rule,
49
+ dryRun,
50
+ anchored,
51
+ interactive,
46
52
  pathIgnored
47
53
  });
48
54
 
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 ((argument === null) && !dryRun) {
67
- console.log(NO_ARGUMENT_GIVEN_MESSAGE);
68
- } else {
69
- const string = argument; ///
68
+ if (argument === null) {
69
+ if (!dryRun && !interactive) {
70
+ console.log(NO_ARGUMENT_GIVEN_MESSAGE);
71
+
72
+ break;
73
+ }
74
+ }
70
75
 
71
- findAction(string, dryRun, format, quietly);
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
 
@@ -2,20 +2,36 @@
2
2
 
3
3
  const { shellUtilities } = require("necessary");
4
4
 
5
- const { ruleFromStringAnchoredAndDirectory } = require("../../utilities/rule"),
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 { path, directory } = context,
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, {
@@ -11,9 +11,15 @@ function ruleOperation(proceed, abort, context) {
11
11
  return;
12
12
  }
13
13
 
14
- const { string } = context,
15
- directory = false,
16
- anchored = false,
14
+ const { interactive } = context;
15
+
16
+ if (interactive) {
17
+ proceed();
18
+
19
+ return;
20
+ }
21
+
22
+ const { string, anchored, directory } = context,
17
23
  rule = ruleFromStringAnchoredAndDirectory(string, anchored, directory);
18
24
 
19
25
  if (rule === null) {
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
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "find-cli",
3
3
  "author": "James Smith",
4
- "version": "1.5.0",
4
+ "version": "1.6.2",
5
5
  "license": "MIT, Anti-996",
6
6
  "homepage": "https://github.com/djalbat/find-cli",
7
7
  "description": "An alternative to grep.",