Skip to content

Conversation

@iamkroot
Copy link
Contributor

@iamkroot iamkroot commented Nov 22, 2025

We inject a usage map into the Tera context so that the args/flags can be accessed like {{usage.foo}}.

The map is also injected during (deprecated) spec-parsing so that this phase essentially becomes a no-op.

Related to #6766


Note

Expose parsed task args/flags as a usage map in Tera run scripts (including defaults during spec parsing), plus docs and tests.

  • Tasks/Parser:
    • Inject usage map into Tera context for run scripts using parsed args/flags (parse_run_scripts_with_args).
    • During spec-only and initial parsing, build and insert default usage map from usage::Spec to allow {{ usage.* }} without errors.
    • Add helpers: make_usage_ctx (snake_case keys, booleans/strings/arrays) and make_usage_ctx_from_spec_defaults (handles var/count/boolean defaults).
  • Tests:
    • Add e2e/tasks/test_task_usage_map_tera covering basic flags, variadic args arrays, and hyphenated names -> snake_case.
    • Add unit tests for usage map exposure and MultiString handling in task_script_parser.rs.
  • Docs:
    • Update docs/tasks/task-arguments.md and docs/templates.md to document the usage map in Tera scripts, key naming (snake_case or bracket access), value types, and examples.

Written by Cursor Bugbot for commit 80cb98f. This will update automatically on new commits. Configure here.

Copilot AI review requested due to automatic review settings November 22, 2025 06:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a new experimental setting task.disable_spec_from_run_scripts that allows users to opt out of parsing task run scripts for usage specifications. When enabled, the usage spec will be derived solely from the usage field, bypassing template processing of arg(), option(), or flag() calls in run scripts. This restores previous behavior and improves performance by avoiding unnecessary template rendering.

Key Changes:

  • Added conditional logic in TaskScriptParser to skip spec collection from run scripts when the setting is enabled
  • Introduced a new make_usage_ctx helper to populate template context with parsed usage values
  • Added comprehensive tests to verify the new setting and usage context functionality

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/task/task_script_parser.rs Modified spec collection methods to check the new setting and conditionally skip template-based spec parsing; added helper function for usage context creation and tests
settings.toml Added configuration entry for the new disable_spec_from_run_scripts experimental option

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@iamkroot iamkroot changed the title feat: add experimental option to disable spec collection from run scripts feat: add usage to tera context in run scripts Nov 30, 2025
@iamkroot iamkroot requested review from Copilot and jdx November 30, 2025 18:40
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@iamkroot
Copy link
Contributor Author

Should be ready to merge

@jdx
Copy link
Owner

jdx commented Dec 1, 2025

bugbot run

@jdx
Copy link
Owner

jdx commented Dec 1, 2025

this needs e2e tests

Krut Patel and others added 12 commits December 1, 2025 22:47
…ipts

Introduced a new setting `task.disable_spec_from_run_scripts` in `settings.toml` to allow users to opt out of parsing task run scripts for usage specifications. When enabled, the usage spec will be derived solely from the `usage` field, ignoring any `arg()`, `option()`, or `flag()` templates in run scripts. This change aims to restore previous behavior and improve performance by avoiding unnecessary template processing.

Updated the `TaskScriptParser` to respect this new setting during spec collection, ensuring that the behavior aligns with user preferences. Added tests to verify the functionality of the new option.

Related to jdx#6766
@iamkroot iamkroot changed the title feat: add usage to tera context in run scripts feat(tasks): add usage to tera context in run scripts Dec 2, 2025
@iamkroot iamkroot changed the title feat(tasks): add usage to tera context in run scripts feat(tasks): add usage args to Tera context in run scripts Dec 2, 2025
@jdx
Copy link
Owner

jdx commented Dec 2, 2025

bugbot run

let name = flag.name.to_snake_case();
let value = if flag.var {
// Option-like flags with values
tera::Value::String(flag.default.clone().unwrap_or_default())
Copy link

Choose a reason for hiding this comment

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

Bug: Variadic value flags get inconsistent types during parsing

The make_usage_ctx_from_spec_defaults function creates a String for variadic flags (flag.var = true), rather than an Array. This is inconsistent with how variadic arguments are handled and with make_usage_ctx. As a result, templates expecting an array for these flags will encounter type mismatches during spec parsing.

Fix in Cursor Fix in Web

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jdx This has revealed a bug/underspecification in usage.
I am punting it for now for the sake of getting this merged. Further discussion in jdx/usage#387

Krut Patel and others added 4 commits December 2, 2025 04:56
@jdx jdx merged commit b0fffaf into jdx:main Dec 2, 2025
27 checks passed
@iamkroot iamkroot deleted the tera-usage branch December 2, 2025 16:10
iamkroot pushed a commit to iamkroot/mise that referenced this pull request Dec 3, 2025
jdx pushed a commit that referenced this pull request Dec 4, 2025
### 🚀 Features

- **(config)** add support for netrc by @RobotSupervisor in
[#7164](#7164)
- **(lock)** add resolve_lock_info to core backends for checksum
fetching by @jdx in [#7180](#7180)
- **(ruby)** Install ruby from a zip file over HTTPS by @KaanYT in
[#7167](#7167)
- **(tasks)** add `usage` args to Tera context in run scripts by
@iamkroot in [#7041](#7041)

### 🐛 Bug Fixes

- **(lock)** validate platform qualifiers when reading from lockfile by
@jdx in [#7181](#7181)
- **(task)** retry shebang scripts on ETXTBUSY by @iamkroot in
[#7162](#7162)
- **(ui)** remove duplicate 'mise' prefix in verbose footer output by
@jdx in [#7174](#7174)

### 📦️ Dependency Updates

- bump usage-lib to 2.9.0 by @jdx in
[#7177](#7177)

### 📦 Registry

- remove duplicated ubi and github backends from gping by @risu729 in
[#7144](#7144)
- disable bashly test (not working in CI) by @jdx in
[#7173](#7173)
- disable cfn-lint test (failing in CI) by @jdx in
[#7176](#7176)

### Chore

- add fd to mise.toml by @blampe in
[#7178](#7178)

### New Contributors

- @RobotSupervisor made their first contribution in
[#7164](#7164)

## 📦 Aqua Registry Updates

#### New Packages (2)

- [`Kitware/CMake`](https://github.com/Kitware/CMake)
- [`quarto-dev/quarto-cli`](https://github.com/quarto-dev/quarto-cli)

#### Updated Packages (6)

- [`apache/jena`](https://github.com/apache/jena)
- [`apache/spark`](https://github.com/apache/spark)
-
[`danielfoehrKn/kubeswitch`](https://github.com/danielfoehrKn/kubeswitch)
-
[`danielfoehrKn/kubeswitch/switch-sh`](https://github.com/danielfoehrKn/kubeswitch/switch-sh)
- [`evilmartians/lefthook`](https://github.com/evilmartians/lefthook)
- [`updatecli/updatecli`](https://github.com/updatecli/updatecli)
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