diff --git a/bin/cli.js b/bin/cli.js index 5db7178..adf8ed8 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -10,17 +10,13 @@ program .name(name) .description(description) .version(version) - .usage('[options] ') + .argument('', 'the partial/dependency path to resolve') .option('-c, --config ', 'location of a RequireJS config file for AMD') .option('-f, --filename ', 'file containing the dependency') .option('-d, --directory ', 'directory containing all files') .showHelpAfterError() .parse(); -if (program.args.length === 0) { - program.help(); -} - const partial = program.args[0]; const { filename, config } = program.opts(); diff --git a/test/cli.test.js b/test/cli.test.js new file mode 100644 index 0000000..a351897 --- /dev/null +++ b/test/cli.test.js @@ -0,0 +1,21 @@ +/* eslint-env mocha */ + +'use strict'; + +const assert = require('assert').strict; +const process = require('process'); +const { spawnSync } = require('child_process'); +const path = require('path'); + +const cliPath = path.resolve(__dirname, '..', 'bin', 'cli.js'); + +describe('lookup-amd CLI', () => { + it('prints error and exits 1 when path argument is missing', () => { + const result = spawnSync(process.execPath, [cliPath], { + encoding: 'utf8' + }); + + assert.equal(result.status, 1); + assert.match(result.stderr, /error: missing required argument 'path'/); + }); +});