cargo
cargo copied to clipboard
--config with an alias doesn't work, but produces a confusing error message
Problem
Using --config with nightly to specify an alias, and then immediately calling that alias, fails with a confusing error message:
$ cargo +nightly --config 'alias.foo="build"' foo
error: no such subcommand: `foo`
Did you mean `foo`?
Steps
cargo new namecd namecargo +nightly --config 'alias.foo="build"' foo
Possible Solution(s)
Either the alias should work, or the error message should change in this case.
Notes
No response
Version
cargo 1.64.0-nightly (dbff32b27 2022-06-24)
release: 1.64.0-nightly
commit-hash: dbff32b27893b899ae2397f3d56d1be111041d56
commit-date: 2022-06-24
host: x86_64-unknown-linux-gnu
libgit2: 1.4.2 (sys:0.14.2 vendored)
libcurl: 7.83.1-DEV (sys:0.4.55+curl-7.83.1 vendored ssl:OpenSSL/1.1.1n)
os: Arch Linux [64-bit]
In cargo, we first run
let (expanded_args, global_args) = expand_aliases(config, args, vec![])?;
and later call
config_configure(config, &expanded_args, subcommand_args, global_args)?;
which reads the --config flag.
Resolving this would be challenging because config_configure does a lot of processing and handles the layering. Incrementally building up the configuration as we gather the information would take a lot of work.
I'll note I don't personally actually care about this case working, I was just playing around to see if a cargo-watch feature using this pattern would be viable, was not super surprised it didn't work, but thought the error message could be improved. Doing this instead does work, interestingly:
$ env CARGO_ALIAS_FOO=build cargo foo