|
1 | 1 | import { describe, expect, it } from "vitest"; |
2 | 2 |
|
3 | | -import { parseCliArgs } from "./cliArgs.ts"; |
| 3 | +import { parseCliArgs } from "./cliArgs"; |
4 | 4 |
|
5 | 5 | describe("parseCliArgs", () => { |
6 | 6 | it("returns empty result for empty string", () => { |
@@ -102,4 +102,33 @@ describe("parseCliArgs", () => { |
102 | 102 | it("ignores bare -- with no flag name", () => { |
103 | 103 | expect(parseCliArgs("--")).toEqual({ flags: {}, positionals: [] }); |
104 | 104 | }); |
| 105 | + |
| 106 | + it("boolean flag does not consume next token as value", () => { |
| 107 | + expect(parseCliArgs(["--github-output", "1.2.3"], { booleanFlags: ["github-output"] })).toEqual( |
| 108 | + { |
| 109 | + flags: { "github-output": null }, |
| 110 | + positionals: ["1.2.3"], |
| 111 | + }, |
| 112 | + ); |
| 113 | + }); |
| 114 | + |
| 115 | + it("non-boolean flag still consumes next token", () => { |
| 116 | + expect(parseCliArgs(["--root", "/path", "1.2.3"], { booleanFlags: ["github-output"] })).toEqual( |
| 117 | + { |
| 118 | + flags: { root: "/path" }, |
| 119 | + positionals: ["1.2.3"], |
| 120 | + }, |
| 121 | + ); |
| 122 | + }); |
| 123 | + |
| 124 | + it("mixes boolean and value flags with positionals", () => { |
| 125 | + expect( |
| 126 | + parseCliArgs(["--github-output", "--root", "/path", "1.2.3"], { |
| 127 | + booleanFlags: ["github-output"], |
| 128 | + }), |
| 129 | + ).toEqual({ |
| 130 | + flags: { "github-output": null, root: "/path" }, |
| 131 | + positionals: ["1.2.3"], |
| 132 | + }); |
| 133 | + }); |
105 | 134 | }); |
0 commit comments