diff --git a/src/lib/options.test.ts b/src/lib/options.test.ts index 9e72e01..efe9e1f 100644 --- a/src/lib/options.test.ts +++ b/src/lib/options.test.ts @@ -42,15 +42,21 @@ describe("getOpt", () => { expectOpts("cmd -unsolicited", {}).toEqual([ { error: "cmd: -unsolicited is not a switch this command knows about" }, ])); + it("doesn't count quoted words as switches", () => + expectOpts('cmd "-purple"', { purple: 0 }).toEqual([ + { purple: false }, + "-purple", + ])); it("doesn't count switches as positional arguments", () => expectOpts("cmd -yellow banana", { $min: 1, $max: 1, yellow: 0 }).toEqual([ { yellow: true }, "banana", ])); - it("doesn't count quoted words as switches", () => - expectOpts('cmd "-purple"', { purple: 0 }).toEqual([ - { purple: false }, - "-purple", + it("can mix positional and switch arguments", () => + expectOpts("cmd early -lunch noon evening", { lunch: 1 }).toEqual([ + { lunch: ["noon"] }, + "early", + "evening", ])); }); diff --git a/src/lib/options.ts b/src/lib/options.ts index 410d14b..2935d2c 100644 --- a/src/lib/options.ts +++ b/src/lib/options.ts @@ -146,8 +146,8 @@ function getOptCore
( ]; } else { const takeUntil = i + switchArgCount; - for (i++; i <= takeUntil; i++) { - (flags[switchName] as TextPiece[]).push(textPieces[i]); + for (; i < takeUntil; i++) { + (flags[switchName] as TextPiece[]).push(textPieces[i + 1]); } } }