Skip to content

CLI gen: shared option set for request schemas reused across operations #346

Description

@HavenDV

Part of #338. Depends on gap #1 (per-parameter flags).

Today

Once gap #1 lands, each operation gets its own per-property flag list. For schemas reused across multiple operations (Firecrawl's ScrapeOptions is used by scrape, batch-scrape, and embedded in crawl), that produces:

  • duplicated Option<T> field definitions across multiple .g.cs files (drift risk)
  • no way to share a single --flag set under a prefix (--scrape-* in crawl)

Firecrawl's hand-written CliOptions.CreateScrapeOptionSet() returns a record with 28 options, used bare in scrape and prefixed --scrape-* in crawl. ~250 lines of careful manual wiring.

Target

When the generator detects a schema used as a request body or nested-in-request-body in 2+ operations:

  1. Emit a single OptionSet static class with all the per-property Option<T> fields.
  2. Each consuming command imports the option set bare or prefixed.
# bare (when ScrapeOptions IS the body)
firecrawl scrape <url> --only-main-content --formats markdown

# prefixed (when ScrapeOptions is nested inside CrawlRequest.scrapeOptions)
firecrawl crawl <url> --scrape-only-main-content --scrape-formats markdown

Proposed approach

  1. Detect reuse: walk all operation request bodies (plus recursive into nested objects); any ModelData referenced 2+ times qualifies as an option set candidate.
  2. Generate <ModelName>OptionSet class with one static Option<T?> per scalar/array/enum property and a Bind(parseResult) method returning the populated model.
  3. Per-command consumption:
    • bare: command.Options.Add(ScrapeOptionsOptionSet.OnlyMainContent); ...
    • prefixed: a WithPrefix(\"scrape-\") factory that returns aliased Option<T> instances pointing at the same backing schema.
  4. Vendor extension x-cli-option-set: false to opt out (always inline).
  5. Collision rule: when both a top-level body property and a prefixed nested property would produce --max-depth, the top-level wins and the nested becomes --<prefix>-max-depth.

Acceptance criteria

  • Regenerating Firecrawl produces one ScrapeOptionsOptionSet.g.cs shared between scrape and crawl.
  • firecrawl crawl <url> --scrape-only-main-content --scrape-formats markdown works.
  • No duplicated Option<T> field definitions across .g.cs files for the same schema property.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions