diff --git a/package.json b/package.json index fe61e48..6784ca6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@decodo/cli", - "version": "0.1.8", + "version": "0.1.9", "description": "Official CLI for the Decodo APIs", "license": "MIT", "type": "module", diff --git a/src/scrape/services/command-builder.ts b/src/scrape/services/command-builder.ts index 8d39f4f..a2a7acd 100644 --- a/src/scrape/services/command-builder.ts +++ b/src/scrape/services/command-builder.ts @@ -58,6 +58,7 @@ function addPropertyOption( if (propertySchema.type === "boolean") { command.option(`--${kebabFlag}`, help); + command.option(`--no-${kebabFlag}`, help); return; } diff --git a/tests/scrape/services/command-builder.test.ts b/tests/scrape/services/command-builder.test.ts index 3108a7c..47e638d 100644 --- a/tests/scrape/services/command-builder.test.ts +++ b/tests/scrape/services/command-builder.test.ts @@ -44,6 +44,16 @@ describe("configureTargetCommand", () => { expect(config.primaryField).toBe("product_id"); expect(command.registeredArguments).toHaveLength(1); }); + + it("registers a --no- negation alongside boolean options", () => { + const command = new Command("universal"); + configureTargetCommand(command, "universal", schema); + + expect(command.options.some((opt) => opt.long === "--markdown")).toBe(true); + expect(command.options.some((opt) => opt.long === "--no-markdown")).toBe( + true + ); + }); }); describe("buildScrapeBody", () => { @@ -150,4 +160,42 @@ describe("buildScrapeBody", () => { markdown: false, }); }); + + it("lets --no-markdown send markdown: false for universal", () => { + const command = new Command("universal"); + command.exitOverride(); + const config = configureTargetCommand(command, "universal", schema); + command.action(() => undefined); + + command.parse(["https://example.com", "--no-markdown"], { from: "user" }); + expect(command.opts().markdown).toBe(false); + + const body = buildScrapeBody( + "universal", + "https://example.com", + command.opts(), + config, + schema + ); + expect(body.markdown).toBe(false); + }); + + it("keeps the markdown default when the flag is omitted for universal", () => { + const command = new Command("universal"); + command.exitOverride(); + const config = configureTargetCommand(command, "universal", schema); + command.action(() => undefined); + + command.parse(["https://example.com"], { from: "user" }); + expect(command.opts().markdown).toBeUndefined(); + + const body = buildScrapeBody( + "universal", + "https://example.com", + command.opts(), + config, + schema + ); + expect(body.markdown).toBe(true); + }); });