Skip to content

Set usage arguments and flag as environment variables before running the command #4070

Closed
@jdx

Description

Discussed in #4069

Originally posted by gturi January 12, 2025
I think it would be very useful to make mise populate the environment with the arguments and flags declared in the usage section before running the run section. In this way, tasks definition is made inside toml configuration, while their complex "implementation" is left inside the actual script.

[tasks.add-user]
description = "Add a user"
usage = '''
arg "<user>" default="unknown"
complete "user" run="mise run list-users-completion"
'''
run = 'node /path/to/test.js'

[tasks.list-users-completion]
hide = true
quiet = true
description = "List users"
run = 'echo "alice bob charlie"'
// test.js
const { usage_user } = process.env;

console.log(`Adding user '${usage_user}'`);

Current output: Adding user 'undefined'

This enhancement also avoids the declaration of arguments both in usage and run section to make them work:

[tasks.add-user]
description = "Add a user"
usage = '''
arg "<user>"
'''
# the following definition feels a bit redundant 
# since I have already defined "user" argument in the usage section
run = 'echo {{arg(name="user")}}'
#run = 'echo $usage_user' # does not work

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions