find-cli 1.4.11 → 1.5.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.
package/README.md CHANGED
@@ -56,6 +56,8 @@ Options:
56
56
  --dry-run|-d Traverse the directories and files only
57
57
 
58
58
  --quietly|-q Do not show the directory and file path matching
59
+
60
+ --format|-f Formatted output, shown only once the search completes.
59
61
  ```
60
62
 
61
63
  ### Setup
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
 
3
- const { HELP_OPTION, VERSION_OPTION, DRY_RUN_OPTION, QUIETLY_OPTION } = require("./options");
3
+ const { HELP_OPTION, FORMAT_OPTION, VERSION_OPTION, DRY_RUN_OPTION, QUIETLY_OPTION } = require("./options");
4
4
 
5
5
  module.exports = {
6
6
  "h": HELP_OPTION,
7
+ "f": FORMAT_OPTION,
7
8
  "v": VERSION_OPTION,
8
9
  "d": DRY_RUN_OPTION,
9
10
  "q": QUIETLY_OPTION
@@ -7,7 +7,7 @@ const ruleOperation = require("../operation/rule"),
7
7
  const { S, EMPTY_STRING } = require("../constants"),
8
8
  { executeOperations } = require("../utilities/operation");
9
9
 
10
- function findAction(string, dryRun, quietly) {
10
+ function findAction(string, dryRun, format, quietly) {
11
11
  const operations = [
12
12
  ruleOperation,
13
13
  readConfigurationOperation,
@@ -22,6 +22,7 @@ function findAction(string, dryRun, quietly) {
22
22
  context = {
23
23
  string,
24
24
  dryRun,
25
+ format,
25
26
  quietly,
26
27
  rule,
27
28
  lines,
@@ -32,13 +33,15 @@ function findAction(string, dryRun, quietly) {
32
33
  };
33
34
 
34
35
  executeOperations(operations, (completed) => {
35
- logLines(context);
36
+ if (format) {
37
+ logLines(context);
38
+ }
36
39
 
37
40
  if (!completed) {
38
41
  return;
39
42
  }
40
43
 
41
- logTottals(context);
44
+ logTotals(context);
42
45
  }, context);
43
46
  }
44
47
 
@@ -62,13 +65,13 @@ function logLines(context) {
62
65
  requiredContentLength = maximumContentLength; ///
63
66
 
64
67
  lines.forEach((line) => {
65
- const message = line.asMessage(requiredIndexLength, requiredContentLength);
68
+ const formattedMessage = line.asFormattedMessage(requiredIndexLength, requiredContentLength);
66
69
 
67
- console.log(message);
70
+ console.log(formattedMessage);
68
71
  });
69
72
  }
70
73
 
71
- function logTottals(context) {
74
+ function logTotals(context) {
72
75
  const { linesTotal, filesTotal, directoriesTotal, occurrencesTotal } = context,
73
76
  optionalS = (occurrencesTotal === 1) ?
74
77
  EMPTY_STRING :
@@ -29,6 +29,8 @@ Options:
29
29
 
30
30
  --quietly|-q Do not show the directory and file path matching
31
31
 
32
+ --format|-f Formatted output, shown only once the search completes.
33
+
32
34
  Further information:
33
35
 
34
36
  Please see the readme file on GitHub:
package/bin/defaults.js CHANGED
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
2
 
3
3
  const DEFAULT_HELP = false,
4
+ DEFAULT_FORMAT = false,
4
5
  DEFAULT_VERSION = false,
5
6
  DEFAULT_DRY_RUN = false,
6
7
  DEFAULT_QUIETLY = false;
7
8
 
8
9
  module.exports = {
9
10
  DEFAULT_HELP,
11
+ DEFAULT_FORMAT,
10
12
  DEFAULT_VERSION,
11
13
  DEFAULT_DRY_RUN,
12
14
  DEFAULT_QUIETLY
package/bin/find.js CHANGED
@@ -7,7 +7,7 @@ const Line = require("./line");
7
7
  const { readFile } = fileSystemUtilities;
8
8
 
9
9
  function find(filePath, context) {
10
- const { rule } = context,
10
+ const { rule, format } = context,
11
11
  content = readFile(filePath),
12
12
  lines = linesFromContentAndFilePath(content, filePath);
13
13
 
@@ -26,11 +26,17 @@ function find(filePath, context) {
26
26
  occurrencesTotal
27
27
  });
28
28
 
29
- const { lines } = context;
29
+ line.setOccurrences(occurrences);
30
30
 
31
- lines.push(line);
31
+ if (!format) {
32
+ const message = line.asMessage();
32
33
 
33
- line.setOccurrences(occurrences);
34
+ console.log(message);
35
+ } else {
36
+ const { lines } = context;
37
+
38
+ lines.push(line);
39
+ }
34
40
  }
35
41
 
36
42
  linesTotal++;
package/bin/line.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  const { arrayUtilities } = require("necessary");
4
4
 
5
- const { grey, blue, yellow, cyan } = require("./utilities/log"),
5
+ const { grey, blue, yellow } = require("./utilities/log"),
6
6
  { EMPTY_STRING, SINGLE_SPACE } = require("./constants");
7
7
 
8
8
  const { backwardsForEach } = arrayUtilities;
@@ -128,7 +128,7 @@ class Line {
128
128
 
129
129
  gap = grey(gap); ///
130
130
 
131
- match = cyan(match); ///
131
+ match = blue(match); ///
132
132
 
133
133
  string = `${string}${match}${gap}`;
134
134
  });
@@ -142,13 +142,18 @@ class Line {
142
142
  const filePathLength = this.getFilePathLength(),
143
143
  paddingLength = requiredFilePathLength - filePathLength,
144
144
  padding = paddingFromPaddingLength(paddingLength),
145
- filePath = `${this.filePath}${padding}`,
146
- formattedFilePath = blue(filePath);
145
+ formattedFilePath = `${this.filePath}${padding}`;
147
146
 
148
147
  return formattedFilePath;
149
148
  }
150
149
 
151
- asMessage(requiredIndexLength, requiredFilePathLength) {
150
+ asMessage() {
151
+ const message = `${this.filePath} ${this.index} | ${this.content}`;
152
+
153
+ return message;
154
+ }
155
+
156
+ asFormattedMessage(requiredIndexLength, requiredFilePathLength) {
152
157
  const formattedIndex = this.getFormattedIndex(requiredIndexLength),
153
158
  formattedContent = this.getFormattedContent(),
154
159
  formattedFilePath = this.getFormattedFilePath(requiredFilePathLength),
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_DRY_RUN, DEFAULT_QUIETLY } = require("./defaults"),
12
+ { DEFAULT_FORMAT, DEFAULT_DRY_RUN, DEFAULT_QUIETLY } = require("./defaults"),
13
13
  { FIND_COMMAND,
14
14
  HELP_COMMAND,
15
15
  VERSION_COMMAND,
@@ -19,7 +19,7 @@ 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 { dryRun = DEFAULT_DRY_RUN, quietly = DEFAULT_QUIETLY } = options;
22
+ const { format = DEFAULT_FORMAT, dryRun = DEFAULT_DRY_RUN, quietly = DEFAULT_QUIETLY } = options;
23
23
 
24
24
  switch (command) {
25
25
  case HELP_COMMAND: {
@@ -68,7 +68,7 @@ function main(command, argument, options) {
68
68
  } else {
69
69
  const string = argument; ///
70
70
 
71
- findAction(string, dryRun, quietly);
71
+ findAction(string, dryRun, format, quietly);
72
72
  }
73
73
 
74
74
  break;
@@ -100,11 +100,19 @@ function findInFile(filePath, callback, context) {
100
100
  const { quietly } = context;
101
101
 
102
102
  if (!quietly) {
103
- const { ruleString } = context;
103
+ let message;
104
104
 
105
- let message = filePathIgnored ?
106
- red(`Ignore ${filePath}`) :
107
- green(`Permit ${filePath}`);
105
+ const { format, ruleString } = context;
106
+
107
+ message = filePathIgnored ?
108
+ `Ignore ${filePath}`:
109
+ `Permit ${filePath}`;
110
+
111
+ if (format) {
112
+ message = filePathIgnored ?
113
+ red(message) :
114
+ green(message);
115
+ }
108
116
 
109
117
  message = `${message} ${ruleString}`;
110
118
 
@@ -157,11 +165,19 @@ function findInDirectory(directoryPath, callback, context) {
157
165
  const { quietly } = context;
158
166
 
159
167
  if (!quietly) {
160
- const { ruleString } = context;
168
+ let message;
169
+
170
+ const { format, ruleString } = context;
171
+
172
+ message = directoryPathIgnored ?
173
+ `Ignore ${directoryPath}/` :
174
+ `Permit ${directoryPath}/`;
161
175
 
162
- let message = directoryPathIgnored ?
163
- red(`Ignore ${directoryPath}/`) :
164
- green(`Permit ${directoryPath}/`);
176
+ if (format) {
177
+ message = directoryPathIgnored ?
178
+ red(message) :
179
+ green(message);
180
+ }
165
181
 
166
182
  message = `${message} ${ruleString}`;
167
183
 
package/bin/options.js CHANGED
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
2
 
3
3
  const HELP_OPTION = "help",
4
+ FORMAT_OPTION = "format",
4
5
  VERSION_OPTION = "version",
5
6
  QUIETLY_OPTION = "quietly",
6
7
  DRY_RUN_OPTION = "dry-run";
7
8
 
8
9
  module.exports = {
9
10
  HELP_OPTION,
11
+ FORMAT_OPTION,
10
12
  VERSION_OPTION,
11
13
  QUIETLY_OPTION,
12
14
  DRY_RUN_OPTION
@@ -3,10 +3,8 @@
3
3
  const RED_FOREGROUND_COLOUR = "\u001b[31m",
4
4
  GREY_FOREGROUND_COLOUR = "\u001b[90m",
5
5
  BLUE_FOREGROUND_COLOUR = "\u001b[34m",
6
- CYAN_FOREGROUND_COLOUR = "\u001b[36m",
7
6
  GREEN_FOREGROUND_COLOUR = "\u001b[32m",
8
7
  YELLOW_FOREGROUND_COLOUR = "\u001b[33m",
9
- MAGENTA_FOREGROUND_COLOUR = "\u001b[35m",
10
8
  RESET_FOREGROUND_COLOUR = "\u001b[39m";
11
9
 
12
10
  function red(string) { return `${RED_FOREGROUND_COLOUR}${string}${RESET_FOREGROUND_COLOUR}`; }
@@ -15,20 +13,14 @@ function grey(string) { return `${GREY_FOREGROUND_COLOUR}${string}${RESET_FOREGR
15
13
 
16
14
  function blue(string) { return `${BLUE_FOREGROUND_COLOUR}${string}${RESET_FOREGROUND_COLOUR}`; }
17
15
 
18
- function cyan(string) { return `${CYAN_FOREGROUND_COLOUR}${string}${RESET_FOREGROUND_COLOUR}`; }
19
-
20
16
  function green(string) { return `${GREEN_FOREGROUND_COLOUR}${string}${RESET_FOREGROUND_COLOUR}`; }
21
17
 
22
18
  function yellow(string) { return `${YELLOW_FOREGROUND_COLOUR}${string}${RESET_FOREGROUND_COLOUR}`; }
23
19
 
24
- function magenta(string) { return `${MAGENTA_FOREGROUND_COLOUR}${string}${RESET_FOREGROUND_COLOUR}`; }
25
-
26
20
  module.exports = {
27
21
  red,
28
22
  grey,
29
23
  blue,
30
- cyan,
31
24
  green,
32
- yellow,
33
- magenta
25
+ yellow
34
26
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "find-cli",
3
3
  "author": "James Smith",
4
- "version": "1.4.11",
4
+ "version": "1.5.0",
5
5
  "license": "MIT, Anti-996",
6
6
  "homepage": "https://github.com/djalbat/find-cli",
7
7
  "description": "An alternative to grep.",