Skip to content

Commit

Permalink
feat(args): support arbitrary length aliases
Browse files Browse the repository at this point in the history
- update parseKey() to allow any length aliases
- add test
  • Loading branch information
postspectacular committed Mar 22, 2021
1 parent 820dc56 commit 1cfdf49
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/args/src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const parseKey = <T extends IObjectOf<any>>(
if (a === "--") return { state: 1 };
id = camel(a.substr(2));
} else {
id = aliases[a[1]];
id = aliases[a.substr(1)];
!id && illegalArgs(`unknown option: ${a}`);
}
const spec: ArgSpecExt = specs[id];
Expand Down
13 changes: 13 additions & 0 deletions packages/args/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,17 @@ describe("args", () => {
{ result: { a: 1 }, index: 3, done: false, rest: ["ignore"] }
);
});

it("long alias", () => {
assert.deepStrictEqual(
parse<{ a?: string }>(
{ a: string({ alias: "aaa" }) },
["-aaa", "a"],
{
start: 0,
}
),
{ result: { a: "a" }, index: 2, done: true, rest: [] }
);
});
});

0 comments on commit 1cfdf49

Please sign in to comment.