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

Check if command is 'oas' before throwing error #62

Merged
merged 5 commits into from
Aug 27, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
21 changes: 15 additions & 6 deletions cmds/oas.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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();
});
});
};
6 changes: 6 additions & 0 deletions test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
});
});
});