diff --git a/src/parse.ts b/src/parse.ts index 04e1cb3..e4e0be2 100644 --- a/src/parse.ts +++ b/src/parse.ts @@ -47,6 +47,7 @@ export class Parser } private readonly context: any + private currentFlag?: Flags.IOptionFlag constructor(private readonly input: T) { const {pickBy} = m.util this.context = input.context || {} @@ -92,6 +93,7 @@ export class Parser { + it('flag multiple with flag in the middle', () => { + const out = parse(['--foo=bar', '--foo', '100', '--hello', 'world'], { + flags: {foo: flags.string({multiple: true}), hello: flags.string()}, + }) + expect(out.flags).to.deep.include({foo: ['bar', '100']}) + expect(out.flags).to.deep.include({hello: 'world'}) + }) + + it('flag multiple without flag in the middle', () => { + const out = parse(['--foo', './a.txt', './b.txt', './c.txt', '--hello', 'world'], { + flags: {foo: flags.string({multiple: true}), hello: flags.string()}, + }) + expect(out.flags).to.deep.include({foo: ['./a.txt', './b.txt', './c.txt']}) + expect(out.flags).to.deep.include({hello: 'world'}) + }) + + it('flag multiple with arguments', () => { + const out = parse(['--foo', './a.txt', './b.txt', './c.txt', '--', '15'], { + args: [{name: 'num'}], + flags: {foo: flags.string({multiple: true})}, + }) + expect(out.flags).to.deep.include({foo: ['./a.txt', './b.txt', './c.txt']}) + expect(out.args).to.deep.include({num: '15'}) + }) + }) + describe('defaults', () => { it('defaults', () => { const out = parse([], {