Skip to content
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
24 changes: 23 additions & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function _global_options(argv) {
flags.push(def_flag(argv['log-file'], (argv['log-file']) ? '--log-file' : '--no-log-file'));
flags.push(def_flag(argv['elapsed-time'], (argv['elapsed-time']) ? '--elapsed-time' : '--no-elapsed-time'));
flags.push(def_flag(argv['no-color'], '--no-color'));
/* Number type */
/* Numeric type */
flags.push(def_flag(argv.verbose, '--verbose', argv.verbose));
/* String type */
flags.push(def_flag(argv.proxy, '--proxy', argv.proxy));
Expand All @@ -177,6 +177,23 @@ function _global_options(argv) {
return flags;
}

/**
* Check any invalid arguments or options.
* @param { JSON } (argv - Argument vector.
* @return Return true if there is no input error.
*/
function _check_argv(argv) {
/* Numeric type */
if (argv.verbose !== undefined &&
// this must exclude NaN -- yargs default value for numeric type
!(argv.verbose >= 0 && argv.verbose <= 5)) {
console.warn("invalid value for --verbose option: must be a number between 0 and 5");
return false;
}

return true;
}

/**
* Form elisp script path.
* @param { string } name - Name of the script without extension.
Expand Down Expand Up @@ -212,6 +229,11 @@ async function e_call(argv, script, ...args) {
return;
}

if (!_check_argv(argv)) {
process.exit(1);
return;
}

return new Promise(resolve => {
let _path = el_script(script);

Expand Down
Loading