Skip to content

Commit 5bfd5c8

Browse files
authored
Add provided set to cli parser (AssemblyScript#1273)
1 parent 5fdd1d6 commit 5bfd5c8

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

cli/util/options.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ interface Result {
3131
/** Normal arguments. */
3232
arguments: string[],
3333
/** Trailing arguments. */
34-
trailing: string[]
34+
trailing: string[],
35+
/** Provided arguments from the cli. */
36+
provided: Set<string>
3537
}
3638

3739
/** Parses the specified command line arguments according to the given configuration. */

cli/util/options.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function parse(argv, config) {
2121
var unknown = [];
2222
var arguments = [];
2323
var trailing = [];
24+
var provided = new Set();
2425

2526
// make an alias map and initialize defaults
2627
var aliases = {};
@@ -53,9 +54,13 @@ function parse(argv, config) {
5354
else { arguments.push(arg); continue; } // argument
5455
}
5556
if (option) {
56-
if (option.type == null || option.type === "b") options[key] = true; // flag
57-
else {
57+
if (option.type == null || option.type === "b") {
58+
options[key] = true; // flag
59+
provided.add(key);
60+
} else {
61+
// the argument was provided
5862
if (i + 1 < argv.length && argv[i + 1].charCodeAt(0) != 45) { // present
63+
provided.add(key);
5964
switch (option.type) {
6065
case "i": options[key] = parseInt(argv[++i], 10); break;
6166
case "I": options[key] = (options[key] || []).concat(parseInt(argv[++i], 10)); break;
@@ -82,7 +87,7 @@ function parse(argv, config) {
8287
}
8388
while (i < k) trailing.push(argv[i++]); // trailing
8489

85-
return { options, unknown, arguments, trailing };
90+
return { options, unknown, arguments, trailing, provided };
8691
}
8792

8893
exports.parse = parse;

0 commit comments

Comments
 (0)