-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate-args.js
More file actions
31 lines (29 loc) · 794 Bytes
/
validate-args.js
File metadata and controls
31 lines (29 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const { error } = require('./util');
function validateArgs(argv, options, command) {
let normalizedOptions = options
.map(option => option.name.split(','))
.reduce((acc, val) => acc.concat(val), []);
normalizedOptions = normalizedOptions.map(option => {
option = option.trim();
if (option.startsWith('--')) {
return option.substr(2);
} else if (option.startsWith('-')) {
return option.substr(1);
}
});
for (const arg in argv) {
if (arg === '_') {
// ignore this arg
continue;
}
if (!normalizedOptions.includes(arg)) {
error(
`Invalid argument ${arg} passed to ${command}. Please refer to 'sciterjs-cli ${command} --help' for full list of options.\n\n`
);
throw new Error('Invalid argument found.');
}
}
}
module.exports = {
validateArgs,
};