Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --verbose flag #37

Merged
merged 4 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ jobs:
fail-fast: false
matrix:
node-version:
- 20
- 18
- 16
- 14
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand Down
19 changes: 18 additions & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@ 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
Expand All @@ -25,14 +34,22 @@ const cli = meow(`
type: 'boolean',
alias: 'd',
},
verbose: {
type: 'boolean',
alias: 'v',
},
},
});

if (cli.input.length === 0) {
console.error('Specify at least one path');
process.exitCode = 1;
} else {
const files = await deleteAsync(cli.input, cli.flags);
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'));
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@
"cross-platform"
],
"dependencies": {
"del": "^7.0.0",
"del": "^7.1.0",
"meow": "^10.1.3"
},
"devDependencies": {
"ava": "^4.3.1",
"execa": "^6.1.0",
"temp-write": "^5.0.0",
"xo": "^0.50.0"
"xo": "^0.56.0"
}
}
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ $ del --help
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
Expand Down
11 changes: 11 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,14 @@ test('main', async t => {
await execa('./cli.js', ['--force', filename]);
t.false(fs.existsSync(filename));
});

test('verbose file exists', async t => {
const filename = tempWrite.sync('foo');
const {stdout} = await execa('./cli.js', ['--force', '--verbose', filename]);
t.is(stdout, filename);
});

test('verbose file does not exist', async t => {
const {stdout} = await execa('./cli.js', ['--verbose', 'does-not-exist.txt']);
t.is(stdout, '');
});