-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathcli.js
executable file
·57 lines (48 loc) · 1.12 KB
/
cli.js
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
52
53
54
55
56
57
#!/usr/bin/env node
import process from 'node:process';
import meow from 'meow';
import {deleteAsync} from 'del';
const logEvent = event => {
if (event.path !== undefined) {
console.log(event.path);
}
};
const noop = () => {};
const cli = meow(`
Usage
$ del <path|glob> …
Options
--force, -f Allow deleting the current working directory and outside
--dry-run, -d List what would be deleted instead of deleting
--verbose, -v Display the absolute path of files and directories as they are deleted
Examples
$ del unicorn.png rainbow.png
$ del "*.png" "!unicorn.png"
`, {
importMeta: import.meta,
flags: {
force: {
type: 'boolean',
shortFlag: 'f',
},
dryRun: {
type: 'boolean',
shortFlag: 'd',
},
verbose: {
type: 'boolean',
shortFlag: 'v',
},
},
});
if (cli.input.length === 0) {
console.error('Specify at least one path');
process.exitCode = 1;
} else {
const {verbose, ...flags} = cli.flags;
const onProgress = verbose ? logEvent : noop;
const files = await deleteAsync(cli.input, {onProgress, ...flags});
if (cli.flags.dryRun) {
console.log(files.join('\n'));
}
}