Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Allow passing arguments/options/flags to subtasks #3759

Closed
bartsmykla opened this issue Dec 21, 2024 · 1 comment
Closed

Allow passing arguments/options/flags to subtasks #3759

bartsmykla opened this issue Dec 21, 2024 · 1 comment

Comments

@bartsmykla
Copy link

bartsmykla commented Dec 21, 2024

Problem

Mise doesn’t currently support passing dynamic arguments, options, or flags from a main task to its subtasks. This makes it difficult to create workflows where all subtasks share a common argument, like a policy name.

Here are possible approaches to solve this:

Inline argument substitution

["generate:policy"]
depends = [
    "generate:tools:policy-gen",
    "generate:policy:core-resources {{ arg(name='policy-name') }}",
    "generate:policy:other-resources {{ arg(name='policy-name') }}",
]

["generate:policy:core-resources"]
depends = ["generate:tools:policy-gen"]

run = """
echo "Generating core resources for {{ arg(name='policy-name') }}"
"""

["generate:policy:other-resources"]
depends = [
    "generate:tools:policy-gen",
    "generate:policy:core-resources {{ arg(name='policy-name') }}",
]

run = """
echo "Generating other resources for {{ arg(name='policy-name') }}"
"""

Automatic argument passing

["generate:policy"]
pass_args_to_depends = true  # Automatically pass arguments to subtasks

depends = ["generate:tools:policy-gen", "generate:policy:core-resources", "generate:policy:other-resources"]

["generate:policy:core-resources"]
depends = ["generate:tools:policy-gen"]

run = """
echo "Generating core resources for {{ arg(name='policy-name') }}"
"""

["generate:policy:other-resources"]
depends = ["generate:tools:policy-gen", "generate:policy:core-resources"]

run = """
echo "Generating other resources for {{ arg(name='policy-name') }}"
"""

Using environment variables from parent task

["generate:policy"]
env.POLICY_NAME = "{{ arg(name='policy-name') }}"

depends = ["generate:tools:policy-gen", "generate:policy:core-resources", "generate:policy:other-resources"]

["generate:policy:core-resources"]
depends = ["generate:tools:policy-gen"]

run = """
echo "Generating core resources for {{ env.POLICY_NAME }}"
"""

["generate:policy:other-resources"]
depends = ["generate:tools:policy-gen", "generate:policy:core-resources"]

run = """
echo "Generating other resources for {{ env.POLICY_NAME }}"
"""

Expected Behavior

When running:

mise run generate:policy circuit-breaker

All subtasks should receive the circuit-breaker argument. Expected output:

Generating core resources for circuit-breaker
Generating other resources for circuit-breaker

Benefits

  • Makes workflows easier by reducing repeated code when subtasks use the same arguments
  • Lets you pass arguments dynamically to adjust subtask behavior
  • Keeps tasks cleaner and simpler to manage
@jdx
Copy link
Owner

jdx commented Dec 21, 2024

I don't think this is necessary. You can just set an environment variable like this:

[tasks."generate:policy"]
run = "POLICY_NAME=circuit-breaker mise run generate:tools:policy-gen ::: generate:policy:core-resources ::: generate:policy:other-resources"

Repository owner locked and limited conversation to collaborators Dec 21, 2024
@jdx jdx converted this issue into discussion #3760 Dec 21, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

2 participants