Skip to content

Commit aaf2949

Browse files
committed
Require CLI filename argument
1 parent 0862287 commit aaf2949

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

bin/cli.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ program
1010
.name(name)
1111
.description(description)
1212
.version(version)
13+
.argument('<filename>', 'the path to file to examine')
1314
.usage('[options] <filename>')
1415
.option('-d, --directory <path>', 'location of files of supported filetypes')
1516
.option('-c, --require-config <path>', 'path to a requirejs config')
1617
.option('-w, --webpack-config <path>', 'path to a webpack config')
1718
.option('-t, --ts-config <path>', 'path to a typescript config')
1819
.option('--list-form', 'output the list form of the tree (one element per line)')
20+
.showHelpAfterError()
1921
.parse();
2022

2123
const cliOptions = program.opts();

test/cli.test.mjs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { strict as assert } from 'node:assert';
2+
import { spawnSync } from 'node:child_process';
3+
import path from 'node:path';
4+
import process from 'node:process';
5+
import { fileURLToPath } from 'node:url';
6+
7+
const testDir = path.dirname(fileURLToPath(import.meta.url));
8+
const cliPath = path.resolve(testDir, '..', 'bin', 'cli.js');
9+
10+
describe('dependency-tree CLI', () => {
11+
it('prints usage and exits when filename is missing', () => {
12+
const result = spawnSync(process.execPath, [cliPath], {
13+
encoding: 'utf8'
14+
});
15+
16+
assert.equal(result.status, 1);
17+
assert.match(result.stderr, /error: missing required argument 'filename'/);
18+
assert.match(result.stderr, /Usage: dependency-tree \[options] <filename>/);
19+
});
20+
});

0 commit comments

Comments
 (0)