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

feat: add rest of tera features for templates #2582

Merged
merged 9 commits into from
Sep 15, 2024
18 changes: 18 additions & 0 deletions docs/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ The following context objects are available inside templates:
- `cwd: PathBuf` – current working directory
- `config_root: PathBuf` – directory containing the `mise.toml` file or directory containing
`.mise` directory with config file.
- `mise_bin` - the path to the current mise executable
- `mise_pid` - the pid of the current mise process
- `xdg_cache_home` - the directory of XDG cache home
- `xdg_config_home` - the directory of XDG config home
- `xdg_data_home` - the directory of XDG data home
- `xdg_state_home` - the directory of XDG state home

As well as these functions:

Expand All @@ -20,6 +26,18 @@ As well as these functions:
- `os() -> String` – return the operating system, e.g. `linux`, `macos`, `windows`
- `os_family() -> String` – return the operating system family, e.g. `unix`, `windows`
- `num_cpus() -> usize` – return the number of CPUs on the system
- `error(message) -> String` - Abort execution and report error `message` to user.
- `choice(n, alphabet)` - Generate a string of `n` with random sample with replacement
of `alphabet`. For example, `choice('64', HEX)` will generate a random
64-character lowercase hex string.
- `datetime()` - Return local time with ISO 8601 format
- `datetime(format)` - Return local time with `format`. Read the
[`chrono` library docs](https://docs.rs/chrono/latest/chrono/format/strftime/index.html)
for the format
- `datetime_utc()` - Return UTC time with ISO 8601 format
- `datetime_utc(format)` - Return UTC time with `format`. Read the
[`chrono` library docs](https://docs.rs/chrono/latest/chrono/format/strftime/index.html)
for the format

And these filters:

Expand Down
2 changes: 2 additions & 0 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::collections::{HashMap, HashSet};
pub use std::env::*;
use std::path;
use std::path::PathBuf;
use std::process;
use std::string::ToString;
use std::sync::RwLock;
use std::time::Duration;
Expand Down Expand Up @@ -126,6 +127,7 @@ pub static MISE_BIN: Lazy<PathBuf> = Lazy::new(|| {
.or_else(|| current_exe().ok())
.unwrap_or_else(|| "mise".into())
});
pub static MISE_PID: Lazy<String> = Lazy::new(|| process::id().to_string());
pub static __MISE_SCRIPT: Lazy<bool> = Lazy::new(|| var_is_true("__MISE_SCRIPT"));
pub static __MISE_DIFF: Lazy<EnvDiff> = Lazy::new(get_env_diff);
pub static __MISE_ORIG_PATH: Lazy<Option<String>> = Lazy::new(|| var("__MISE_ORIG_PATH").ok());
Expand Down
Loading
Loading