diff --git a/src/util.js b/src/util.js index 1445500a..646a8e6e 100644 --- a/src/util.js +++ b/src/util.js @@ -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)); @@ -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. @@ -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);