Description
Problem
Sometimes cargo commands require -p
to refer to a package (e.g. cargo tree
and cargo upgrade
from cargo-edit
), so I've developed a habit of just always typing -p
. This got me a surprising failure when running
cargo add -p crates-io-crate
error: the following required arguments were not provided:
<DEP_ID|--path <PATH>|--git <URI>>
Usage: cargo add [OPTIONS] <DEP>[@<VERSION>] ...
cargo add [OPTIONS] --path <PATH> ...
cargo add [OPTIONS] --git <URL> ...
I didn't expect to be told an argument is missing, because I thought I have provided it.
Due to --path
and --git
mentioned, at first I thought that -p
was only for adding git or path dependencies (similar to how cargo install
needs both a git url and a crate name).
I've ran --help
to check what -p
does, and the discrepancy between DEP_ID
and [<SPEC>]
distracted me from noticing "Package to modify" below.
I took me a while to notice that -p
refers to the workspace, and not to the new package I wanted to add.
Proposed Solution
I'd be great if Cargo could check the value of the -p
argument despite the arguments parsing failure. The external crate name is extremely unlikely to match any name in the workspace, so Cargo could detect that and report plainly that -p
is the wrong place for the new crate name.
At very least the help for -p
could include something like "The current workspace package".
Notes
cargo 1.87.0-nightly (a6c604d 2025-03-26)