-
Notifications
You must be signed in to change notification settings - Fork 128
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
How to set environment variables conditionally depending on command line arguments. #876
Comments
there is no condition on cli arg, but you can look at env setup scripts: this for example, will set the env var only if you provided at least 1 arg on the cargo-make command and will run at the start of every cargo-make invocation. env_scripts = [
'''
#!@duckscript
arg_defined = is_defined 1
if ${arg_defined}
set_env MY_ENV_VAR "arg is provided"
end
'''
] |
@hydra and here is the exact script you need env_scripts = [
'''
#!@duckscript
for arg in ${@}
verbose_found = eq ${arg} verbose
if ${verbose_found}
set_env RUSTC_LOG rustc_codegen_ssa::back::link=info
goto :postloop
end
end
:postloop
'''
] |
Firstly, thanks for the reply and scripts, much appreciated. But hmm, I didn't really want to resort to have to writing scripts in yet another programming language that I don't know (duckscript) or have no real desire to learn - and neither do I want to force the rest of the devs working on the project to have to learn duckscript. I kinda just wanted some built-in syntax to achieve it, with examples in the main documentation, something like
Conditions option when setting an environment variable seems like a reasonable thing to want to do, we already have conditions for tasks, so all the condition logic is probably implemented, except for the 'arg_set' condition, and the application of conditions to environment variables. Perhaps 'arg_not_set', 'args', 'args_contains', etc, in the same manner as 'env*' conditions for tasks, would also be very useful. Thoughts? |
duckscript is similar to simple shell but much more limited and simple. not much to learn.
Conditions are supported for env vars, but that type of condition does not exist. |
Yup, and that was appreciated! I will look at duckscript next time I work on the cargo make files for the project, in doesn't fill me with joy though.
I would love for someone else to, and I'm happy to try any PRs and give feedback, but alas my time is split too many ways right now for me to delve into the cargo make codebase and make a PR myself. |
Feature Description
After skimming and searching the docs I cannot find out how to conditionally set or modify environment variables based on command line arguments.
When the 'verbose' argument is present on the command line, as above, the following environment variable needs to be set:
My use-case is that I need to see output from the linker sometimes (e.g. on CI server logs) and locally when builds fail, and also want a less-verbose build before pushing via git.
My tasks require specific 'target' setting, features, cargo args and cwd, and I use a cargo workspace.
Here's an excerpt from the
Makefile.toml
Did I miss something in the documentation? I read up on: tasks, conditions (they're for tasks), environment variables (creating ones, globals, etc), and arguments.
The text was updated successfully, but these errors were encountered: