Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix boolean regexp in flags #582

Merged
merged 1 commit into from
Sep 4, 2019
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions flags/bool_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,14 @@ test(function booleanParsingFalse(): void {

assertEquals(parsed.boool, false);
});

test(function booleanParsingTrueLike(): void {
const parsed = parse(["-t", "true123"], { boolean: ["t"] });
assertEquals(parsed.t, true);

const parsed2 = parse(["-t", "123"], { boolean: ["t"] });
assertEquals(parsed2.t, true);

const parsed3 = parse(["-t", "false123"], { boolean: ["t"] });
assertEquals(parsed3.t, true);
});
2 changes: 1 addition & 1 deletion flags/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export function parse(
) {
setArg(key, args[i + 1], arg);
i++;
} else if (args[i + 1] && /true|false/.test(args[i + 1])) {
} else if (args[i + 1] && /^(true|false)$/.test(args[i + 1])) {
setArg(key, args[i + 1] === "true", arg);
i++;
} else {
Expand Down