Skip to content

Commit dfe7adf

Browse files
authored
fix: validate ncu-ci args (#411)
1 parent 1163952 commit dfe7adf

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

bin/ncu-ci

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ const Request = require('../lib/request');
2323
const CLI = require('../lib/cli');
2424
const yargs = require('yargs');
2525

26+
const commandKeys = [
27+
'rate',
28+
'walk',
29+
'url',
30+
'pr',
31+
'commit'
32+
];
33+
2634
// eslint-disable-next-line no-unused-vars
2735
const argv = yargs
2836
.command({
@@ -115,13 +123,20 @@ const argv = yargs
115123
default: false,
116124
describe: 'Write the results as markdown to clipboard'
117125
})
118-
.option('json', {
126+
.option('json <path>', {
119127
type: 'string',
120-
describe: 'Write the results as json to the path'
128+
describe: 'Write the results as json to <path>'
121129
})
122-
.option('markdown', {
130+
.option('markdown <path>', {
123131
type: 'string',
124-
describe: 'Write the results as markdown to the path'
132+
describe: 'Write the results as markdown to <path>'
133+
}).check(argv => {
134+
if (argv.markdown && commandKeys.includes(argv.markdown)) {
135+
throw new Error('--markdown <path> did not specify a valid path');
136+
} else if (argv.json && commandKeys.includes(argv.json)) {
137+
throw new Error('--json <path> did not specify a valid path');
138+
}
139+
return true;
125140
})
126141
.help()
127142
.argv;

0 commit comments

Comments
 (0)