-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·51 lines (43 loc) · 978 Bytes
/
Copy pathcli.js
File metadata and controls
executable file
·51 lines (43 loc) · 978 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
44
45
46
47
48
49
50
51
#!/usr/bin/env node
import process from 'node:process';
import meow from 'meow';
import {findUpSync, findUpMultipleSync} from 'find-up';
const cli = meow(`
Usage
$ find-up <filename>
Options
--cwd=<directory> Working directory
--all Output all matching files, not just the first
Example
$ echo $PWD
/Users/sindresorhus/foo/bar
$ find-up unicorn.png
/Users/sindresorhus/unicorn.png
$ find-up unicorn.png --all
/Users/sindresorhus/foo/unicorn.png
/Users/sindresorhus/unicorn.png
`, {
importMeta: import.meta,
flags: {
cwd: {
type: 'string',
},
all: {
type: 'boolean',
},
},
});
if (cli.input.length === 0) {
console.error('Specify a filename');
process.exit(1);
}
const findUp = cli.flags.all ? findUpMultipleSync : findUpSync;
let filePath = findUp(cli.input[0], cli.flags);
if (cli.flags.all) {
filePath = filePath.join('\n');
}
if (filePath) {
console.log(filePath);
} else {
process.exitCode = 1;
}