Skip to content

Commit f32b531

Browse files
authoredAug 31, 2023
Add --verbose flag (#37)
1 parent dde9e11 commit f32b531

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed
 

‎cli.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,22 @@ import process from 'node:process';
33
import meow from 'meow';
44
import {deleteAsync} from 'del';
55

6+
const logEvent = event => {
7+
if (event.path !== undefined) {
8+
console.log(event.path);
9+
}
10+
};
11+
12+
const noop = () => {};
13+
614
const cli = meow(`
715
Usage
816
$ del <path|glob> …
917
1018
Options
1119
--force, -f Allow deleting the current working directory and outside
1220
--dry-run, -d List what would be deleted instead of deleting
21+
--verbose, -v Display the absolute path of files and directories as they are deleted
1322
1423
Examples
1524
$ del unicorn.png rainbow.png
@@ -25,14 +34,22 @@ const cli = meow(`
2534
type: 'boolean',
2635
alias: 'd',
2736
},
37+
verbose: {
38+
type: 'boolean',
39+
alias: 'v',
40+
},
2841
},
2942
});
3043

3144
if (cli.input.length === 0) {
3245
console.error('Specify at least one path');
3346
process.exitCode = 1;
3447
} else {
35-
const files = await deleteAsync(cli.input, cli.flags);
48+
const {verbose, ...flags} = cli.flags;
49+
50+
const onProgress = verbose ? logEvent : noop;
51+
52+
const files = await deleteAsync(cli.input, {onProgress, ...flags});
3653

3754
if (cli.flags.dryRun) {
3855
console.log(files.join('\n'));

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"cross-platform"
5151
],
5252
"dependencies": {
53-
"del": "^7.0.0",
53+
"del": "^7.1.0",
5454
"meow": "^10.1.3"
5555
},
5656
"devDependencies": {

‎readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ $ del --help
2323
Options
2424
--force, -f Allow deleting the current working directory and outside
2525
--dry-run, -d List what would be deleted instead of deleting
26+
--verbose, -v Display the absolute path of files and directories as they are deleted
2627
2728
Examples
2829
$ del unicorn.png rainbow.png

‎test.js

+11
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,14 @@ test('main', async t => {
88
await execa('./cli.js', ['--force', filename]);
99
t.false(fs.existsSync(filename));
1010
});
11+
12+
test('verbose file exists', async t => {
13+
const filename = tempWrite.sync('foo');
14+
const {stdout} = await execa('./cli.js', ['--force', '--verbose', filename]);
15+
t.is(stdout, filename);
16+
});
17+
18+
test('verbose file does not exist', async t => {
19+
const {stdout} = await execa('./cli.js', ['--verbose', 'does-not-exist.txt']);
20+
t.is(stdout, '');
21+
});

0 commit comments

Comments
 (0)
Please sign in to comment.