8000 fix(task): allow args to be used with tera tests by risu729 · Pull Request #4605 · jdx/mise · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(task): allow args to be used with tera tests #4605

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

Merged
merged 12 commits into from
Mar 18, 2025

Conversation

risu729
Copy link
Contributor
@risu729 risu729 commented Mar 11, 2025

This PR enables the use of arg, option, and flag in task templates within if conditions or similar syntaxes.

Current Behavior

Currently, placeholders are replaced only after the Tera template is fully rendered. So, expressions like the following:

[tasks.test]
run = "echo {% if flag(name='test') == 'true' %}test is true{% endif %}"

would incorrectly render mise test --test as just echo because 'MISE_TASK_ARG:test:MISE_TASK_ARG' != 'true'.

Changes

Since we need to parse the usage spec before rendering the full Tera template, this PR adds the second rendering after the usage spec is processed. This ensures that expressions with nest like this are evaluated correctly.

[tasks.test]
run = "echo {% if flag(name=env.FLAG_NAME) == 'true' %}TRUE{% endif %}"

Re-rendering the template might introduce some performance overhead, but I believe it's the simplest solution for this.
Of course, templates with more nests cannot be parsed correctly, but it is impossible if we are using usage to parse args in the template.

I still need to fix this PR to avoid code duplication and handle escapes, but I’d like to hear your thoughts on this approach.


Apologies for creating a PR directly. I was debugging locally and wanted to share the idea.

@risu729
Copy link
Contributor Author
risu729 commented Mar 16, 2025

Depending on jdx/usage#252, as usage::parse::ParseValue was not cloneable.

@risu729 risu729 marked this pull request as ready for review March 16, 2025 14:49
@jdx jdx enabled auto-merge (squash) March 18, 2025 13:42
@jdx jdx merged commit 6d07ed1 into jdx:main Mar 18, 2025
18 checks passed
@risu729 risu729 deleted the parse-args-with-if branch March 18, 2025 15:42
jdx pushed a commit that referenced this pull request Mar 21, 2025
### 🐛 Bug Fixes

- **(node)** skip gpg verification of sig file not found by
[@jdx](https://github.com/jdx) in
[#4663](#4663)
- **(task)** allow args to be used with tera tests by
[@risu729](https://github.com/risu729) in
[#4605](#4605)
- Fix syntax error on `activate nu` when PATH contains shims by
[@atty303](https://github.com/atty303) in
[#4349](#4349)

### 🚜 Refactor

- **(registry)** use ubi for yamlscript by
[@scop](https://github.com/scop) in
[#4670](#4670)

### 📚 Documentation

- Fix typo in java.md by [@hverlin](https://github.com/hverlin) in
[#4672](#4672)

### ◀️ Revert

- "chore: temporarily disable bootstrap test" by
[@jdx](https://github.com/jdx) in
[#4658](#4658)

### 📦️ Dependency Updates

- update rust crate ctor to 0.4 by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#4553](#4553)

### Chore

- **(registry)** declare copier by
[@looztra](https://github.com/looztra) in
[#4669](#4669)
- Update to the latest version of ubi by
[@autarch](https://github.com/autarch) in
[#4648](#4648)
- bump expr by [@jdx](https://github.com/jdx) in
[#4666](#4666)
- added android-sdk by [@jdx](https://github.com/jdx) in
[#4668](#4668)
- rename mise-php to asdf-php by [@jdx](https://github.com/jdx) in
[#4674](#4674)

### New Contributors

- @atty303 made their first contribution in
[#4349](#4349)
- @looztra made their first contribution in
[#4669](#4669)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0