Skip to content

Commit a40d030

Browse files
claude: Fix create-project --engine validation timing issue
The --engine option's value function was calling executionEngine() during Cliffy's option parsing phase, which happens before the action handler runs initializeProjectContextAndEngines(). This caused "Unknown --engine" errors for all engines since they weren't registered yet. Solution: - Simplified value function to only parse engine:kernel syntax - Moved engine validation to action handler after initialization - Added better error message showing available engines Fixes: quarto create-project --engine markdown (and other engines)
1 parent 0ec129b commit a40d030

File tree

1 file changed

+19
-7
lines changed
  • src/command/create-project

1 file changed

+19
-7
lines changed

src/command/create-project/cmd.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { basename } from "../../deno_ral/path.ts";
99
import { Command } from "cliffy/command/mod.ts";
1010

1111
import { executionEngine, executionEngines } from "../../execute/engine.ts";
12+
import { initializeProjectContextAndEngines } from "../command-utils.ts";
1213

1314
import { projectCreate } from "../../project/project-create.ts";
1415
import {
@@ -26,7 +27,6 @@ const kProjectTypes = projectTypes();
2627
const kProjectTypeAliases = projectTypeAliases();
2728
const kProjectTypesAndAliases = [...kProjectTypes, ...kProjectTypeAliases];
2829

29-
const kExecutionEngines = executionEngines().reverse();
3030
const kEditorTypes = ["source", "visual"];
3131

3232
export const createProjectCommand = new Command()
@@ -48,15 +48,11 @@ export const createProjectCommand = new Command()
4848
)
4949
.option(
5050
"--engine <engine:string>",
51-
`Use execution engine (${kExecutionEngines.join(", ")})`,
51+
"Use execution engine (jupyter, knitr, markdown, ...)",
5252
{
5353
value: (value: string): string[] => {
5454
value = value || kMarkdownEngine;
55-
const engine = executionEngine(value.split(":")[0]);
56-
if (!engine) {
57-
throw new Error(`Unknown --engine: ${value}`);
58-
}
59-
// check for kernel
55+
// Parse engine:kernel syntax
6056
const match = value.match(/(\w+)(:(.+))?$/);
6157
if (match) {
6258
return [match[1], match[3]];
@@ -132,12 +128,28 @@ export const createProjectCommand = new Command()
132128
)
133129
// deno-lint-ignore no-explicit-any
134130
.action(async (options: any, dir?: string) => {
131+
// Initialize project context and register engines (including external ones)
132+
await initializeProjectContextAndEngines(dir);
133+
135134
if (dir === undefined || dir === ".") {
136135
dir = Deno.cwd();
137136
}
138137

139138
const engine = options.engine || [];
140139

140+
// Validate the engine (after engines are initialized)
141+
if (engine[0]) {
142+
const engineInstance = executionEngine(engine[0]);
143+
if (!engineInstance) {
144+
throw new Error(
145+
`Unknown execution engine: ${engine[0]}. ` +
146+
`Available engines: ${
147+
executionEngines().map((e) => e.name).join(", ")
148+
}`,
149+
);
150+
}
151+
}
152+
141153
const envPackages = typeof (options.withVenv) === "string"
142154
? options.withVenv.split(",").map((pkg: string) => pkg.trim())
143155
: typeof (options.withCondaenv) === "string"

0 commit comments

Comments
 (0)