Skip to content
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

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

Open
jdx opened this issue Jan 12, 2025 Discussed in #4069 · 0 comments · May be fixed by #4159
Open

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

jdx opened this issue Jan 12, 2025 Discussed in #4069 · 0 comments · May be fixed by #4159

Comments

@jdx
Copy link
Owner

jdx commented Jan 12, 2025

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
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 a pull request may close this issue.

1 participant