diff --git a/specs/grep/grep.md b/specs/grep/grep.md index 319213e722cdac1d2e34a2f7d5930ecd4535163d..f2124d5c7b07740b9e9e9caf582c10cff8147255 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.