Skip to content

Commit c80f64c

Browse files
authored
fix: resolve alias value over default (#228)
1 parent 3c190d6 commit c80f64c

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

src/_parser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ export function parseRawArgs<T = Record<string, any>>(
170170
if ((out as any)[main] !== undefined && (out as any)[alias] === undefined) {
171171
(out as any)[alias] = (out as any)[main];
172172
}
173+
if ((out as any)[alias] !== (out as any)[main] && defaults[main] === (out as any)[main]) {
174+
(out as any)[main] = (out as any)[alias];
175+
}
173176
}
174177

175178
return out;

test/args.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ describe("args", () => {
4545
{ value: { type: "enum", options: ["one", "two"] } },
4646
{ value: "one", _: [] },
4747
],
48+
[
49+
["--foo-bar", "one"],
50+
{ fooBar: { type: "enum", options: ["one", "two"], default: "two" } },
51+
{ fooBar: "one", "foo-bar": "one", _: [] },
52+
],
4853
] as [string[], ArgsDef, any][])(
4954
"should parsed correctly %o (%o)",
5055
(rawArgs, definition, result) => {

0 commit comments

Comments
 (0)