diff --git a/README.md b/README.md index c5b0f19..a6d2df4 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,7 @@ navigation. | `--compare ` | Compare ref to diff against `--base` | | `--ref ` | Diff scope: `work` (staged + unstaged + untracked), `staged`, or `unstaged` (default: auto-detect) | | `--pr ` | Review a GitHub pull request by number or URL (requires `gh`) | +| `--validate` | Validate chapters without starting the server or opening the browser | | `--instructions ` | One-off instructions for chapter generation (up to 1000 characters; `prep` command) | Examples: diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index af65cd3..e26ae66 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -8,7 +8,7 @@ import { toDiffScopeOptions, } from "./diff-scope-options.js"; import { runPrep } from "./prep.js"; -import { show } from "./show.js"; +import { show, validate } from "./show.js"; const require = createRequire(import.meta.url); const { version } = require("../package.json") as { version: string }; @@ -45,10 +45,17 @@ addDiffScopeOptions( program .command("show") .description("Load a chapters.json file and open it in a local browser") - .argument("", "Path to a chapters.json file"), -).action(async (jsonPath: string, refs: string[], opts: DiffCommandOptions) => { - await show(jsonPath, toDiffScopeOptions(refs, opts)); -}); + .argument("", "Path to a chapters.json file") + .option("--validate", "Validate chapters without starting the server or opening the browser"), +).action( + async (jsonPath: string, refs: string[], opts: DiffCommandOptions & { validate?: boolean }) => { + if (opts.validate) { + await validate(jsonPath, toDiffScopeOptions(refs, opts)); + } else { + await show(jsonPath, toDiffScopeOptions(refs, opts)); + } + }, +); program.addCommand(commentsCommand()); diff --git a/packages/cli/src/show.ts b/packages/cli/src/show.ts index f713fd2..33d12b0 100644 --- a/packages/cli/src/show.ts +++ b/packages/cli/src/show.ts @@ -79,6 +79,10 @@ export async function show(jsonPath: string, options: DiffScopeOptions): Promise closeDb(); } +export async function validate(jsonPath: string, options: DiffScopeOptions): Promise { + await buildChaptersFile(jsonPath, options); +} + interface BuiltChaptersFile { chaptersFile: ChaptersFile; /** The reviewed PR's number when `--pr` was used, else null. */