From 83d0ac8571ed63b1b307b692f3f341254bbbfa9f Mon Sep 17 00:00:00 2001 From: Caleb Sander <caleb.sander@gmail.com> Date: Wed, 10 Feb 2021 21:19:28 -0500 Subject: [PATCH] Clarify npm run grep with arguments --- specs/grep/grep.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/specs/grep/grep.md b/specs/grep/grep.md index 319213e..f2124d5 100644 --- a/specs/grep/grep.md +++ b/specs/grep/grep.md @@ -52,7 +52,8 @@ For example, `some-command | grep ERROR` will print out only the lines of output Implement `grep` (including 4 of its command-line flags) in Node.js. -Your `grep` will be invoked using `npm run grep [-i] [-r] [-v] [-z] pattern [files ...]`. +Your `grep` will be invoked using `npm run grep -- [-i] [-r] [-v] [-z] pattern [files ...]`. +(The `--` just tells `npm` to pass the remaining arguments to `grep.js`.) The flags `-i`, `-r`, `-v`, and `-z` are described later. A simple implementation of `grep` would read the entire input, loop over its lines, and print the lines that match the pattern. @@ -75,15 +76,15 @@ The values should be interpreted as follows: If no filenames are given and `-r` is not used, the standard input (`process.stdin`) should be searched instead. - `recursive` stores whether the flag `-r` was used. If so, `files` are expected to be directories and are searched recursively. - For example, `npm run grep pattern -r dir1 dir2` searches all files in `dir1` and `dir2` (and all their subdirectories) for `pattern`. + For example, `npm run grep -- pattern -r dir1 dir2` searches all files in `dir1` and `dir2` (and all their subdirectories) for `pattern`. If no directories are provided, the current directory (`.`) should be searched instead. You can use the provided function `readdirRecursive()` to search each directory. - `gunzip` stores whether the flag `-z` was used. If so, all files are treated as [gzip](https://en.wikipedia.org/wiki/Gzip)ped text files and are unzipped before being searched. - For example, if `independence.txt` is compressed to `independence.txt.gz`, then `npm run grep -z ss independence.txt.gz` prints the same lines as `npm run grep ss independence.txt`. + For example, if `independence.txt` is compressed to `independence.txt.gz`, then `npm run grep -- -z ss independence.txt.gz` prints the same lines as `npm run grep -- ss independence.txt`. Note that `-z` and `-r` can be used together. - `ignoreCase` stores whether the flag `-i` was used. - If so, the pattern is case-insensitive, e.g. `npm run grep -i error` would match a line containing `error`, `ERROR`, or `ErRoR`. + If so, the pattern is case-insensitive, e.g. `npm run grep -- -i error` would match a line containing `error`, `ERROR`, or `ErRoR`. You can use `RegExp(pattern, 'i')` to make a case-insensitive regular expression. - `invert` stores whether the flag `-v` was used. If so, the pattern specifies lines to *exclude*; only the lines that don't match the pattern are printed. -- GitLab