From 9c63bb52e9a8a15574dd16f2856174d197ac7713 Mon Sep 17 00:00:00 2001 From: Peter Hale Date: Tue, 6 Dec 2022 13:01:58 -0700 Subject: [PATCH] feat: handle custom parser nested array for multiple flag @W-12165862@ --- src/interfaces/parser.ts | 2 +- src/parser/parse.ts | 2 +- test/parser/parse.test.ts | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/interfaces/parser.ts b/src/interfaces/parser.ts index 6b479627..797de0f9 100644 --- a/src/interfaces/parser.ts +++ b/src/interfaces/parser.ts @@ -175,7 +175,7 @@ export type OptionFlagProps = FlagProps & { multiple?: boolean; } -export type FlagParser = (input: I, context: any, opts: P & OptionFlag) => Promise +export type FlagParser = (input: I, context: any, opts: P & OptionFlag) => Promise export type FlagBase = FlagProps & { parse: FlagParser; diff --git a/src/parser/parse.ts b/src/parser/parse.ts index 58557880..0400d649 100644 --- a/src/parser/parse.ts +++ b/src/parser/parse.ts @@ -201,7 +201,7 @@ export class Parser { + const out = await parse( + ['--foo', './a.txt,./b.txt', '--foo', './c.txt', '--', '15'], + { + args: [{name: 'num'}], + flags: {foo: flags.string({ + multiple: true, + parse: async input => input.split(',').map(i => i.trim()), + })}, + }, + ) + expect(out.flags).to.deep.include({ + foo: ['./a.txt', './b.txt', './c.txt'], + }) + expect(out.args).to.deep.include({num: '15'}) + }) }) describe('defaults', () => {