|
2 | 2 | import process from 'node:process';
|
3 | 3 | import meow from 'meow';
|
4 | 4 | import {deleteAsync} from 'del';
|
| 5 | +import {isPresentableError} from 'presentable-error'; |
5 | 6 |
|
6 | 7 | const logEvent = event => {
|
7 | 8 | if (event.path !== undefined) {
|
@@ -45,15 +46,25 @@ if (cli.input.length === 0) {
|
45 | 46 | console.error('Specify at least one path');
|
46 | 47 | process.exitCode = 1;
|
47 | 48 | } else {
|
48 |
| - const {verbose, dryRun, ...flags} = cli.flags; |
| 49 | + try { |
| 50 | + const {verbose, dryRun, ...flags} = cli.flags; |
49 | 51 |
|
50 |
| - // Only use onProgress for verbose mode when not in dry-run |
51 |
| - // In dry-run mode, we print the files at the end instead |
52 |
| - const onProgress = verbose && !dryRun ? logEvent : noop; |
| 52 | + // Only use onProgress for verbose mode when not in dry-run |
| 53 | + // In dry-run mode, we print the files at the end instead |
| 54 | + const onProgress = verbose && !dryRun ? logEvent : noop; |
53 | 55 |
|
54 |
| - const files = await deleteAsync(cli.input, {onProgress, dryRun, ...flags}); |
| 56 | + const files = await deleteAsync(cli.input, {onProgress, dryRun, ...flags}); |
55 | 57 |
|
56 |
| - if (dryRun && files.length > 0) { |
57 |
| - console.log(files.join('\n')); |
| 58 | + if (dryRun && files.length > 0) { |
| 59 | + console.log(files.join('\n')); |
| 60 | + } |
| 61 | + } catch (error) { |
| 62 | + if (isPresentableError(error)) { |
| 63 | + console.error(error.message); |
| 64 | + } else { |
| 65 | + throw error; |
| 66 | + } |
| 67 | + |
| 68 | + process.exitCode = 1; |
58 | 69 | }
|
59 | 70 | }
|
0 commit comments