Skip to content
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
4 changes: 2 additions & 2 deletions ts/packages/dispatcher/dispatcher/src/command/parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ function invalidValueToken(valueToken: string) {
if (
valueToken.length === 2 &&
valueToken[0] === "-" &&
valueToken.charCodeAt(1) < 48 /* "0" */ &&
valueToken.charCodeAt(1) > 57 /* "9" */
(valueToken.charCodeAt(1) < 48 /* "0" */ ||
valueToken.charCodeAt(1) > 57) /* "9" */
) {
return true;
}
Expand Down
28 changes: 28 additions & 0 deletions ts/packages/dispatcher/dispatcher/test/flags.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ describe("Flag parsing", () => {
obj: { description: "testing", type: "json" },
},
} as const;
const shortFlags = {
flags: {
output: {
description: "output",
type: "string",
char: "o",
},
verbose: {
description: "verbose",
type: "boolean",
char: "v",
},
},
} as const;
const o1 = { hello: "str", num: 11, bool: true };
const o2 = { ...o1, obj: o1, arr: [o1, o1] };
it("type", () => {
Expand Down Expand Up @@ -257,6 +271,20 @@ describe("Flag parsing", () => {
}
});

it("does not consume a following short flag as a string value", () => {
expect(() => parseParams("-o -v", shortFlags)).toThrow(
"Missing value for flag '-o'",
);
});

it("accepts a negative numeric-looking string as a short flag value", () => {
expect(parseParams("-o -1", shortFlags).flags.output).toBe("-1");
});

it("accepts a quoted short-flag-looking string as a short flag value", () => {
expect(parseParams("-o '-v'", shortFlags).flags.output).toBe("-v");
});

it("Duplicate flags", () => {
try {
parseParams("--num 10 --num 11", typeFlags);
Expand Down
Loading