fix: restore --template CLI option

Revert the positional-only template change. Keep --template as the primary API; stdin template remains unsupported without a special error.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Yang Jun
2026-07-26 14:16:00 +08:00
co-authored by Cursor
parent 456d7dc6a4
commit ed801e1581
3 changed files with 10 additions and 10 deletions
+1 -1
View File
@@ -46,7 +46,7 @@ npm install liquidjs
**CLI**
```bash
npx liquidjs 'Hello, {{ name }}!' --context '{"name": "Liquid"}'
npx liquidjs --template 'Hello, {{ name }}!' --context '{"name": "Liquid"}'
```
See the [setup guide][setup] for partials, layouts, caching, and other options.
+2 -2
View File
@@ -14,7 +14,7 @@ async function render () {
program
.name('liquidjs')
.description('Render a Liquid template')
.argument('<template>', 'liquid template to render (inline or @path to a file)')
.requiredOption('-t, --template <liquid | @path>', '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,7 +45,7 @@ async function render () {
.parse()
const options = program.opts()
const template = await resolveTemplate(program.args[0])
const template = await resolveTemplate(options.template)
const context = await resolveContext(options.context)
const liquid = new Liquid(options)
const output = liquid.parseAndRenderSync(template, context)
+7 -7
View File
@@ -56,33 +56,33 @@ Pre-built UMD bundles are also available:
LiquidJS can also be used to render a template directly from CLI using `npx`:
```bash
npx liquidjs '{{"hello" | capitalize}}'
npx liquidjs --template '{{"hello" | capitalize}}'
```
You can either pass the template inline (as shown above) or you can read it from a file by using the `@` character followed by a path, like so:
```bash
npx liquidjs @./some-template.liquid
npx liquidjs --template @./some-template.liquid
```
A context can be passed inline, from a path, or piped through `stdin`. The following three are equivalent:
```bash
npx liquidjs 'Hello, {{ name }}!' --context '{"name": "Snake"}'
npx liquidjs 'Hello, {{ name }}!' --context @./some-context.json
echo '{"name": "Snake"}' | npx liquidjs 'Hello, {{ name }}!' --context @-
npx liquidjs --template 'Hello, {{ name }}!' --context '{"name": "Snake"}'
npx liquidjs --template 'Hello, {{ name }}!' --context @./some-context.json
echo '{"name": "Snake"}' | npx liquidjs --template 'Hello, {{ name }}!' --context @-
```
The rendered output is written to `stdout` by default, but you can also specify an output file (if the file exists, it will be overwritten):
```bash
npx liquidjs '{{"hello" | capitalize}}' --output ./hello.txt
npx liquidjs --template '{{"hello" | capitalize}}' --output ./hello.txt
```
You can also pass a number of options to customize template rendering behavior. For example, the `--js-truthy` option can be used to enable JavaScript truthiness:
```bash
npx liquidjs @./some-template.liquid --js-truthy
npx liquidjs --template @./some-template.liquid --js-truthy
```
Most of the [options available through the JavaScript API][options] are also available from the CLI. For help on available options, use `npx liquidjs --help`.