diff --git a/cli.js b/cli.js index ed111800b..c11606999 100644 --- a/cli.js +++ b/cli.js @@ -100,7 +100,10 @@ module.exports = processArgv => { // // Instead of failing out to the user with an undecipherable "Unknown value: ..." error, let's // try to parse their request again but a tad less eager. - if (e.name !== 'UNKNOWN_VALUE' || (e.name === 'UNKNOWN_VALUE' && !argv.version)) { + if ( + (e.name !== 'UNKNOWN_VALUE' || (e.name === 'UNKNOWN_VALUE' && !argv.version)) && + argv.command !== 'oas' + ) { throw e; } diff --git a/cmds/oas.js b/cmds/oas.js index 39b6ff94f..a80a33970 100644 --- a/cmds/oas.js +++ b/cmds/oas.js @@ -1,8 +1,5 @@ -const cp = require('child_process'); +const { spawn } = require('child_process'); const path = require('path'); -const { promisify } = require('util'); - -const spawn = promisify(cp.spawn); exports.command = 'oas'; exports.usage = 'oas'; @@ -13,7 +10,19 @@ exports.position = 1; exports.args = []; exports.run = function() { - return spawn(path.join(__dirname, '..', 'node_modules', '.bin', 'oas'), process.argv.slice(3), { - stdio: 'inherit', + const cp = spawn( + path.join(__dirname, '..', 'node_modules', '.bin', 'oas'), + process.argv.slice(3), + { + stdio: 'inherit', + }, + ); + + return new Promise((resolve, reject) => { + cp.on('close', code => { + if (code && code > 0) return reject(); + + return resolve(); + }); }); }; diff --git a/test/cli.test.js b/test/cli.test.js index 403eb9c44..79a5a898a 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -117,4 +117,10 @@ describe('cli', () => { assert.equal(err.message, 'No project version provided. Please use `--version`.'); }); }); + + it('should not error with oas arguments passed in', () => { + return assert.doesNotReject(() => { + return cli(['oas', 'init']); + }); + }); });