jdx / mise

dev tools, env vars, task runner
https://mise.jdx.dev
MIT License
9.86k stars 281 forks source link

More templating options for run commands in tasks #1864

Open woutor opened 6 months ago

woutor commented 6 months ago

Hi,

I have migrated my noxfile to mise and everything works fine except for one case:

I'd like to adjust my task's run command based on parameters like env vars or arguments. For example, locally I like my linter to fix errors, while in CI it should fail.

For now I have a .mise.toml file like:

[tasks."format:ruff"]
description = "Format the code with ruff"
run = """
#!/usr/bin/env bash
if [ "$CI" == "yes" ]; then
  ruff format myproject tests --check
else
  ruff format myproject tests
fi
"""

...

[tasks.ci]
alias = "default"
description = "Run all CI tasks"
depends = ["format", "lint", "test"]

However, I would like to have something like:

[tasks."format:ruff"]
description = "Format the code with ruff"
run = "ruff format myproject tests {{ if args.ci: '--check' }}"

I understand tasks are still experimental, so thanks for considering this anyway.

jdx commented 6 months ago

yeah this would be nice. One of the things I'm planning is a far more advanced arg parsing logic leveraging the work I'm doing with usage. No idea when I'll have time to finish that but this would be a good addition.

vrslev commented 2 days ago

This would be very useful.

I'd like to be able to pass arbitrary arguments to a task, similar to spread arguments in just:

test *args:
    uv run pytest {{args}}

It could look something like this:

[tasks.test]
run = "uv run pytest {{args}}"