-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Proposal: Command-line config #6699
Comments
This all sounds pretty great to me, thanks for writing this up @ehuss! I think an alternative to I also think that this is definitely pretty hard to invoke on the command line for colorful syntaxes due to the usage of TOML, but that feels appropriate given the target use case here which is advanced configuration. I've seen some various tools take JSON on the command line before for similar use cases so it seems not so bad as well. With regards to your questions:
I think this'd be fine to add to the
Yes. But more seriously, that's how lots of other Cargo things work :) One thing to consider though is that if you specify a relative path in
Could you elaborate a bit on this? Do you mean
Agreed! Good to mention! Not a reason to not do it :) |
Yea, it's not super elegant. There are some advantages that I didn't mention. It makes it possible to safely express things like #6139 which is currently not possible.
Both. I'm just thinking it's a significant addition for something that may not be used often. |
Ah ok, I feel that |
I have also just tripped a situation where this feature would have helped. I have an environment where I have a |
Relatedly, I have just filed #6728 "Want env var specifying overriding config file" |
Having CARGO_INCLUDE env var work is very helpful as we can use other env vars to point to the final location - thank you. |
This is a two-part proposal to make it easier to use Cargo config settings.
--config <key>=<value>
command-line argument for setting config values for the current command.include
key to the config for including other config files.It is intended that the use of these should be relatively rare and only for advanced use cases.
--config
CLI optionThe
--config
command-line option is a global option available to all commands. It sets the given config key to the given value, and takes precedence over all other sources (environment variables and all config files). The argument is parsed as TOML syntax. The--config
flag may be specified multiple times, in which case the values are merged in left-to-right order, using the same merging logic that multiple config files use.Some examples of what it looks like using Bourne shell syntax:
include
keyThe
include
key may be used to include other config files. It may be a string for a path to the file, or a TOML array of strings to include multiple files. The paths are relative to the config file where it is defined, or from the current working directory if used from an environment variable or command-line option.When used in a config file, the include is loaded and merged immediately after the file with the
include
key has been loaded and fully processed. When used from an environment variable (CARGO_INCLUDE
), it is loaded after all config files have been loaded. When used from the command line (--config include=…
), it is loaded after the environment variable has been processed. This will require special handling as normally config values replace and shadow previous ones.In conjunction with
--config
, this can be a convenient way to specify other config files on the command-line:cargo --config 'include=".cargo/config-foo"' …
Users are allowed to use filenames of the form
.cargo/config-*
, though users are free to use other filenames outside of the.cargo
directory.Questions and concerns:
<key>=<value>
may be tricky, because toml-rs does not provide a way to restrict that. It would be easy to restrict to a single value, but would still allow comments, or things like[foo]\nbar=1
. I would prefer to be conservative and only allow a restricted syntax and not allow any free-form TOML, but that may be difficult. If that's a concern, should toml-rs be extended to support this case? How should this be handled?include
via env/cli to be relative to CWD? I think that seems natural, but perhaps the workspace root would be another option? Or maybe a limited env var substitution?--config
option to properly compile something would make IDEs and other tools unable to work properly (or require arduous setup).References:
The text was updated successfully, but these errors were encountered: