Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New minijinja-cli #602

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ test-msrv:
@cd minijinja; cargo test --all-features

.PHONY: test
test: test-msrv
test: test-msrv test-cli
@echo "CARGO TEST MINIJINJA-CONTRIB ALL FEATURES"
@cd minijinja-contrib; cargo test --all-features

5 changes: 4 additions & 1 deletion minijinja-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ completions = ["clap_complete", "clap_complete_nushell", "clap_complete_fig"]
unicode = ["minijinja/unicode"]
ini = ["configparser"]
contrib = ["minijinja-contrib"]
toml = ["dep:toml", "home"]

[dependencies]
anyhow = "1.0.74"
@@ -31,6 +32,7 @@ clap = { version = "4.3.21", default-features = false, features = [
"std",
"cargo",
"help",
"wrap_help",
"usage",
"error-context",
] }
@@ -46,7 +48,7 @@ minijinja = { version = "=2.3.1", path = "../minijinja", features = [
] }
minijinja-contrib = { version = "=2.3.1", optional = true, path = "../minijinja-contrib", features = ["pycompat", "datetime", "timezone", "rand"] }
rustyline = { version = "12.0.0", optional = true }
serde = "1.0.183"
serde = { version = "1.0.183", features = ["derive", "rc"] }
serde_json = "1.0.105"
serde_json5 = { version = "0.1.0", optional = true }
serde_qs = { version = "0.12.0", optional = true }
@@ -57,6 +59,7 @@ clap_complete = { version = "4", optional = true }
clap_complete_fig = { version = "4", optional = true }
clap_complete_nushell = { version = "4", optional = true }
configparser = { version = "3.1.0", optional = true }
home = { version = "0.5.5", optional = true }

[build-dependencies]
clap = { version = "4.3.21", default-features = false, features = [
77 changes: 13 additions & 64 deletions minijinja-cli/README.md
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ You can also install it with [Homebrew](https://brew.sh/)
brew install minijinja-cli
```

## Arguments
## Arguments and Options

`minijinja-cli` has two positional arguments to refer to files. Either one of them can
be set to `-` to read from stdin. This is the default for the template, but only one
@@ -60,68 +60,8 @@ can be set to stdin at once.
When data is read from `stdin`, `--format` must be specified as auto detection
is based on file extensions.

## Options

- `-f`, `--format` `<FORMAT>`:
this defines the input format of the data file. The default is `auto` which
turns on auto detection based on the file extension. For the supported formats
see the next section.
- `-a`, `--autoescape` `<MODE>`:
picks an auto escape mode. The default is auto detection (`auto`) based on
file extension. The options are `none` to disable escaping, `html` to
enable HTML/XML escaping, `json` to enable JSON (YAML compatible)
serialization.
- `-D`, `--define` `<EXPR>`:
defines a variable from an expression. The supported formats are `NAME` to define
the variable `NAME` with the value `true`, `NAME=VALUE` to define the variable
`NAME` with the value `VALUE` as string or `NAME:=VALUE` to set the variable `NAME`
to the YAML interpreted value `VALUE`. When YAML support is not enabled, `:=`
only supports JSON.
- `--strict`:
enables strict mode. Undefined variables will then error upon rendering.
- `--no-include`:
disallows including or extending of templates from the file system.
- `--no-newline`:
Do not output a trailing newline
- `--trim-blocks`:
Enable the trim_blocks flag
- `--lstrip-blocks`:
Enable the lstrip_blocks flag
- `--py-compat`:
Enables improved Python compatibility. Enabling this adds methods such as
`dict.keys` and some others.
- `-s`, `--syntax <PAIR>`:
Changes a syntax feature (feature=value) [possible features: `block-start`, `block-end`, `variable-start`, `variable-end`, `comment-start`, `comment-end`, `line-statement-prefix`, `line-statement-comment`]
- `--safe-path <PATH>`:
Only allow includes from this path. Can be used multiple times.
- `--env`:
passes the environment variables to the template in the variable `ENV`
- `-E`, `--expr` `<EXPR>`:
rather than rendering a template, evaluates an expression instead. What happens
with the result is determined by `--expr-out`.
- `--expr-out` `<MODE>`:
sets the expression output mode. The default is `print`. `print` just prints
the expression output, `json` emits it as JSON serialized value and
`status` hides the output but reports it as exit status. `true` converts to `0`
and `false` converts to `1`. Numeric results are returned unchanged.
- `--fuel` `<AMOUNT>`:
sets the maximum fuel for the engine. When the engine runs out of fuel it will error.
- `--repl`:
spawns an interactive read-eval print loop for MiniJinja expressions.
- `--dump` `<KIND>`:
prints internals of the template. Possible options are `tokens` to see the output
of the tokenizer, `ast` to see the AST after parsing, and `instructions` to inspect
the compiled bytecode.
- `-o`, `--output` `<FILENAME>`:
writes the output to a filename rather than stdout.
- `--select` `<SELECTOR>`:
select a path of the input data.
- `--generate-completion` `<SHELL>`:
generate the completions for the given shell.
- `--version`:
prints the version.
- `--help`:
prints the help.
MiniJinja supports a wide range of options, too long to mention here. For the full help
use `--long-help` or `--help` for a brief summary.

## Formats

@@ -146,6 +86,15 @@ minijinja-cli template.j2 input.ini --section default
Note that not all formats support all input types. For instance querystring
and INI will only support strings for the most part.

## Config File

The config file is in TOML format. By default the file in `~/.minijinja.toml` is loaded
but an alternative path can be supplied with the `--config-file` command line argument
or the `MINIJINJA_CONFIG_FILE` environment variable.

To see what the config file looks like, invoke `minijinja-cli --print-config` which will
print out the current loaded config as TOML (including defaults).

## Selecting

By default the input file is fed directly as context. You can however also
@@ -216,7 +165,7 @@ By default all features are enabled. The following features can be explicitly
selected when the defaults are turned off:

* `yaml`: enables YAML support
* `toml`: enables TOML support
* `toml`: enables TOML support (required for `--config-file` support)
* `cbor`: enables CBOR support
* `json5`: enables JSON5 support (instead of JSON)
* `querystring`: enables querystring support
2 changes: 1 addition & 1 deletion minijinja-cli/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fs::create_dir_all;

pub mod cli {
include!("src/cli.rs");
include!("src/command.rs");
}

fn main() -> std::io::Result<()> {
Loading