-
-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·62 lines (54 loc) · 1.08 KB
/
cli.js
File metadata and controls
executable file
·62 lines (54 loc) · 1.08 KB
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
58
59
60
61
62
#!/usr/bin/env node
import process from 'node:process';
import meow from 'meow';
import {globby} from 'globby';
import trash from 'trash';
// Ignore all flags of `rm` program.
const ignoredFlags = [
'r',
'f',
'i',
'd',
'P',
'R',
'W',
];
const ignoredFlagsConfig = {};
for (const flag of ignoredFlags) {
ignoredFlagsConfig[flag] = {
type: 'boolean',
};
}
const cli = meow(`
Usage
$ trash <path|glob> […]
Options
--dot Match dotfiles when using glob patterns (remember to quote the glob)
--verbose, -v Print trashed items
Examples
$ trash unicorn.png rainbow.png
$ trash '*.png' '!unicorn.png'
`, {
importMeta: import.meta,
flags: {
...ignoredFlagsConfig,
dot: {
type: 'boolean',
},
verbose: {
type: 'boolean',
shortFlag: 'v',
},
},
});
if (cli.input.length === 0) {
console.error('Specify at least one path');
process.exit(1);
}
const files = await globby(cli.input, {expandDirectories: false, onlyFiles: false, dot: cli.flags.dot});
await trash(files);
if (cli.flags.verbose) {
for (const file of files) {
console.log(file);
}
}