Skip to content

Commit

Permalink
fix: parse varargs response type
Browse files Browse the repository at this point in the history
  • Loading branch information
iowillhoit committed Oct 12, 2022
1 parent 4194e3e commit 35b1aa9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export function toHelpSection(
return { header, body };
}

export function parseVarArgs(args: Record<string, unknown>, argv: string[]): Record<string, unknown> {
const final: Record<string, unknown> = {};
export function parseVarArgs(args: Record<string, unknown>, argv: string[]): Record<string, string | undefined> {
const final: Record<string, string | undefined> = {};
const argVals = Object.values(args);

// Remove arguments from varargs
Expand Down
10 changes: 10 additions & 0 deletions test/unit/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ describe('parseVarArgs', () => {
expect(varargs).to.deep.equal({ key1: 'value1' });
});

it('should parse multiple varargs', () => {
const varargs = parseVarArgs({}, ['key1=value1', 'key2=value2']);
expect(varargs).to.deep.equal({ key1: 'value1', key2: 'value2' });
});

it('should allow an empty value', () => {
const varargs = parseVarArgs({}, ['key1=']);
expect(varargs).to.deep.equal({ key1: undefined });
});

it('should parse varargs and not arguments', () => {
const varargs = parseVarArgs({ arg1: 'foobar' }, ['foobar', 'key1=value1']);
expect(varargs).to.deep.equal({ key1: 'value1' });
Expand Down

0 comments on commit 35b1aa9

Please sign in to comment.