Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions docs/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ These variables offer key information about the current environment:
- `config_root: PathBuf` – Locates the directory containing your `mise.toml` file, or in the case of something like `~/src/myproj/.config/mise.toml`, it will point to `~/src/myproj`.
- `mise_bin: String` - Points to the path to the current mise executable
- `mise_pid: String` - Points to the pid of the current mise process
- `mise_env: String` - The configuration environment as specified by `MISE_ENV`, `-E`, or `--env`. Will be undefined if the configuration environment is not set.
- `xdg_cache_home: PathBuf` - Points to the directory of XDG cache home
- `xdg_config_home: PathBuf` - Points to the directory of XDG config home
- `xdg_data_home: PathBuf` - Points to the directory of XDG data home
Expand Down
8 changes: 8 additions & 0 deletions e2e/env/test_env_profiles
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ echo 'env.AAA = "override-2"' >mise.override2.toml
assert "mise env --json | jq -r .AAA" "main"
MISE_ENV=override1 assert "mise env --json | jq -r .AAA" "override-1"
MISE_ENV=override1,override2 assert "mise env --json | jq -r .AAA" "override-2"

cat <<EOF >mise.toml
[tasks.print]
run = '{% if mise_env %}echo {{mise_env}}{% endif %}'
EOF
assert "mise run print" ""
MISE_ENV=env1 assert "mise run print" "[env1]"
MISE_ENV=env1,env2 assert "mise run print" "[env1, env2]"
8 changes: 8 additions & 0 deletions src/tera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ pub static BASE_CONTEXT: Lazy<Context> = Lazy::new(|| {
context.insert("env", &*env::PRISTINE_ENV);
context.insert("mise_bin", &*env::MISE_BIN);
context.insert("mise_pid", &*env::MISE_PID);
if !(&*env::MISE_ENV).is_empty() {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to get this from settings or something because if it's specified as a CLI argument this will miss that (I think, I could be wrong)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I double checked and it looks like it works:

$ cat <<EOF >mise.toml
[tasks.print]
run = '{% if mise_env %}echo {{mise_env}}{% endif %}'
EOF
$ MISE_ENV=production mise run print
[print] $ echo [production]
[production]
$ mise --env production run print
[print] $ echo [production]
[production]

I believe this is because the environment function in src/env.rs reads from both CLI arguments and environment varables.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the sake of completeness, I have added some additional e2e tests (38eb2a6) that cover the different ways the configuration environment can be set.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for checking

context.insert("mise_env", &*env::MISE_ENV);
}
if let Ok(dir) = env::current_dir() {
context.insert("cwd", &dir);
}
Expand Down Expand Up @@ -381,6 +384,11 @@ mod tests {
assert_eq!(render("{{config_root}}"), "/");
}

#[test]
fn test_mise_env() {
assert_eq!(render("{% if mise_env %}{{mise_env}}{% endif %}"), "");
}

#[test]
fn test_cwd() {
assert_eq!(render("{{cwd}}"), "/");
Expand Down