From 5dbdcc4057e9aade6789cc281f42cca75dbee850 Mon Sep 17 00:00:00 2001 From: Joshua Tenner Date: Thu, 14 May 2020 17:43:21 -0400 Subject: [PATCH 1/2] add provided set to cli parser --- cli/util/options.d.ts | 4 +++- cli/util/options.js | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) 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..36f6f2eeb2 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,6 +54,7 @@ function parse(argv, config) { else { arguments.push(arg); continue; } // argument } if (option) { + provided.add(key); if (option.type == null || option.type === "b") options[key] = true; // flag else { if (i + 1 < argv.length && argv[i + 1].charCodeAt(0) != 45) { // present @@ -82,7 +84,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; From c13daae24db3f38e054b3741badfd032e0e863e1 Mon Sep 17 00:00:00 2001 From: Joshua Tenner Date: Thu, 14 May 2020 17:56:20 -0400 Subject: [PATCH 2/2] fix provided location --- cli/util/options.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cli/util/options.js b/cli/util/options.js index 36f6f2eeb2..c0c1232ddf 100644 --- a/cli/util/options.js +++ b/cli/util/options.js @@ -54,10 +54,13 @@ function parse(argv, config) { else { arguments.push(arg); continue; } // argument } if (option) { - provided.add(key); - 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;