Skip to content

Commit 42af75a

Browse files
committed
feat: allow --_varname CLI flags without frontmatter declaration
Template variables can now be passed via CLI without pre-declaring them in frontmatter. If not provided, they still prompt for input. Example - no frontmatter needed: md task.claude.md --_strict yes The variable is used in the body as {{ _strict }}
1 parent 37fedc8 commit 42af75a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/cli-runner.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,23 @@ export class CliRunner {
377377
}
378378
}
379379

380+
// Also extract any --_varname CLI flags not declared in frontmatter
381+
// This allows optional template vars without frontmatter declaration
382+
for (let i = remaining.length - 1; i >= 0; i--) {
383+
const arg = remaining[i];
384+
if (arg.startsWith("--_") && !internalKeys.has(arg.slice(2))) {
385+
const key = arg.slice(2); // Remove --
386+
if (i + 1 < remaining.length && !remaining[i + 1].startsWith("-")) {
387+
templateVars[key] = remaining[i + 1];
388+
remaining.splice(i, 2);
389+
} else {
390+
// Boolean flag without value
391+
templateVars[key] = "true";
392+
remaining.splice(i, 1);
393+
}
394+
}
395+
}
396+
380397
// Inject positional CLI args as template variables (_1, _2, etc.)
381398
// First, separate flags from positional args in remaining
382399
const positionalCliArgs: string[] = [];

0 commit comments

Comments
 (0)