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

Subcommand aliases silently shadow user-defined aliases #6221

Closed
ordovicia opened this issue Oct 25, 2018 · 0 comments · Fixed by #6259
Closed

Subcommand aliases silently shadow user-defined aliases #6221

ordovicia opened this issue Oct 25, 2018 · 0 comments · Fixed by #6259

Comments

@ordovicia
Copy link
Contributor

Problem
Users can define aliases in ~/.cargo/config.
But user-defined b, r, and t aliases do not work because they are shadowed by subcommand aliases (resp. for build, run, and test).
Cargo does not emit any warnings.

Steps

  1. Add the following definition to ~/.cargo/config
[alias]
b = "foo"
  1. Run cargo b
  2. Cargo executes build subcommand, not foo, without any warnings

Notes

  • Current Cargo warns user-defined aliases shadowed by (non-alias) subcommands here:

    cargo/src/bin/cargo/cli.rs

    Lines 121 to 126 in efb7972

    (Some(_), Some(_)) => {
    config.shell().warn(format!(
    "alias `{}` is ignored, because it is shadowed by a built in command",
    cmd
    ))?;
    }
  • I sent a PR that adds c alias for check (Add c alias for check #6218), which will shadow user-defined c aliases.
  • Documenting subcommand aliases would tell people not to define such aliases (Aliases entirely undocumented #4391).

Output of cargo version:
cargo 1.29.0 (524a578d7 2018-08-05)

bors added a commit that referenced this issue Nov 18, 2018
Allow user aliases to override built-in aliases

This PR allows user-defined aliases take precedence over built-in ones, with a warning that tells there exists a built-in alias.
This PR does not allow user aliases override built-in subcommands.

```console
$ cat .cargo/config
[alias]
b = "fetch"
build = "fetch"

$ ./target/debug/cargo b
warning: user-defined alias `b` overrides a built-in alias for `build`

$ ./target/debug/cargo build
warning: user-defined alias `build` is ignored, because it is shadowed by a built-in command
   Compiling proc-macro2 v0.4.19
   Compiling unicode-xid v0.1.0
   Compiling cc v1.0.25
(snip)
```

In the current version of Cargo, user aliases cannot override built-in aliases.
This behavior is keeping us from safely adding new built-in aliases without interfering existing user config.
Merging this PR will allow that.

Fixes #6221
Relating to #6218
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