[READ-ONLY] Mirror of https://github.com/bombshell-dev/args. <1kB CLI flag parser
args args-parser cli command-line command-line-parser node
5

Configure Feed

Select the types of activity you want to include in your feed.

fix(coercion): fix non-value boolean flags (#8)

authored by

René and committed by
GitHub
(Feb 23, 2025, 7:11 PM -0600) 1cf93e05 c8e66428

+22 -1
+1 -1
src/index.ts
··· 56 56 57 57 const coerce = (value?: string, type?: "string" | "boolean" | "array") => { 58 58 if (type === "string") return value; 59 - if (type === "boolean") return !!value; 59 + if (type === "boolean") return value === undefined ? true : value === 'true'; 60 60 61 61 if (!value) return value; 62 62 if (value.length > 3 && BOOL_RE.test(value)) return value === "true";
+21
test/flags.test.ts
··· 257 257 expect(result).toEqual(output); 258 258 }); 259 259 }); 260 + 261 + describe("boolean flags", () => { 262 + it("should handle long-form boolean flags correctly", () => { 263 + const input = ["--add"]; 264 + const opts = { 265 + boolean: ['add'] 266 + }; 267 + const output = { _: [], add: true }; 268 + expect(parse(input, opts)).toEqual(output); 269 + }); 270 + 271 + it("should handle alias boolean flags correctly", () => { 272 + const input = ["-a"]; 273 + const opts = { 274 + boolean: ['add'], 275 + alias: { a: 'add' } 276 + }; 277 + const output = { _: [], add: true }; 278 + expect(parse(input, opts)).toEqual(output); 279 + }); 280 + });