-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·43 lines (36 loc) · 754 Bytes
/
cli.js
File metadata and controls
executable file
·43 lines (36 loc) · 754 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env node
import process from 'node:process';
import meow from 'meow';
import getStdin from 'get-stdin';
import {matcher} from 'matcher';
const cli = meow(`
Usage
$ <input> | matcher <pattern> […]
Options
--case-sensitive Case-sensitive matching
Example
$ ls
cli.js
license
package.json
readme.md
test.js
$ ls | matcher '*.js' '!test.js'
cli.js
`, {
importMeta: import.meta,
flags: {
caseSensitive: {
type: 'boolean',
default: false,
},
},
});
const {input, flags} = cli;
if (input.length === 0) {
console.error('Provide at least one pattern');
process.exit(1);
}
const stdin = await getStdin();
const lines = stdin.split(/\r?\n/);
console.log(matcher(lines, input, flags).join('\n'));