diff --git a/cli/util/options.d.ts b/cli/util/options.d.ts index 0b9dcafff9..d15016b0f4 100644 --- a/cli/util/options.d.ts +++ b/cli/util/options.d.ts @@ -31,7 +31,9 @@ interface Result { /** Normal arguments. */ arguments: string[], /** Trailing arguments. */ - trailing: string[] + trailing: string[], + /** Provided arguments from the cli. */ + provided: Set } /** Parses the specified command line arguments according to the given configuration. */ diff --git a/cli/util/options.js b/cli/util/options.js index 9e201549e6..c0c1232ddf 100644 --- a/cli/util/options.js +++ b/cli/util/options.js @@ -21,6 +21,7 @@ function parse(argv, config) { var unknown = []; var arguments = []; var trailing = []; + var provided = new Set(); // make an alias map and initialize defaults var aliases = {}; @@ -53,9 +54,13 @@ function parse(argv, config) { else { arguments.push(arg); continue; } // argument } if (option) { - if (option.type == null || option.type === "b") options[key] = true; // flag - else { + if (option.type == null || option.type === "b") { + options[key] = true; // flag + provided.add(key); + } else { + // the argument was provided if (i + 1 < argv.length && argv[i + 1].charCodeAt(0) != 45) { // present + provided.add(key); switch (option.type) { case "i": options[key] = parseInt(argv[++i], 10); break; case "I": options[key] = (options[key] || []).concat(parseInt(argv[++i], 10)); break; @@ -82,7 +87,7 @@ function parse(argv, config) { } while (i < k) trailing.push(argv[i++]); // trailing - return { options, unknown, arguments, trailing }; + return { options, unknown, arguments, trailing, provided }; } exports.parse = parse;