feat!: take CLI template as positional argument

Make template a required positional arg (drop --template) for v11 per #586; stdin template remains unsupported without a special error.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Yang Jun
2026-07-24 02:08:59 +08:00
co-authored by Cursor
parent 44712f64fc
commit 456d7dc6a4
3 changed files with 17 additions and 15 deletions
+9 -7
View File
@@ -14,7 +14,7 @@ async function render () {
program
.name('liquidjs')
.description('Render a Liquid template')
.requiredOption('-t, --template <liquid | @path>', 'liquid template to render (inline or @path to a file)') // TODO: Change to argument in 11.0
.argument('<template>', 'liquid template to render (inline or @path to a file)')
.option('-c, --context <json | @path>', 'input context in JSON format (@- to read from stdin)')
.option('-o, --output <path>', 'write rendered output to file (omit to write to stdout)')
.option('--cache [size]', 'cache previously parsed template structures (default cache size: 1024)')
@@ -45,12 +45,7 @@ async function render () {
.parse()
const options = program.opts()
if (options.template === '@-') {
throw new Error(`Reading template from stdin is not supported. Pass an inline template or @path.`)
}
const template = await resolveInputOption(options.template)
const template = await resolveTemplate(program.args[0])
const context = await resolveContext(options.context)
const liquid = new Liquid(options)
const output = liquid.parseAndRenderSync(template, context)
@@ -70,6 +65,13 @@ async function resolveContext (contextOption) {
return context
}
async function resolveTemplate (templateOption) {
if (templateOption && templateOption.startsWith('@') && templateOption !== '@-') {
return resolveInputOption(templateOption)
}
return templateOption
}
async function resolveInputOption (option) {
let content = null
if (option) {