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

fix: validate ncu-ci args #411

Merged
merged 1 commit into from
May 14, 2020
Merged
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
23 changes: 19 additions & 4 deletions bin/ncu-ci
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ const Request = require('../lib/request');
const CLI = require('../lib/cli');
const yargs = require('yargs');

const commandKeys = [
'rate',
'walk',
'url',
'pr',
'commit'
];

// eslint-disable-next-line no-unused-vars
const argv = yargs
.command({
Expand Down Expand Up @@ -115,13 +123,20 @@ const argv = yargs
default: false,
describe: 'Write the results as markdown to clipboard'
})
.option('json', {
.option('json <path>', {
type: 'string',
describe: 'Write the results as json to the path'
describe: 'Write the results as json to <path>'
})
.option('markdown', {
.option('markdown <path>', {
type: 'string',
describe: 'Write the results as markdown to the path'
describe: 'Write the results as markdown to <path>'
}).check(argv => {
if (argv.markdown && commandKeys.includes(argv.markdown)) {
throw new Error('--markdown <path> did not specify a valid path');
} else if (argv.json && commandKeys.includes(argv.json)) {
throw new Error('--json <path> did not specify a valid path');
}
return true;
})
Comment on lines +133 to 140
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use requiresArg: true in the option's definition instead of manual validation

.help()
.argv;
Expand Down