cargo add -p crates-io-crate
could be clearer about what's wrong
#15363
Labels
A-cli
Area: Command-line interface, option parsing, etc.
C-feature-request
Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Command-add
S-needs-design
Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Problem
Sometimes cargo commands require
-p
to refer to a package (e.g.cargo tree
andcargo upgrade
fromcargo-edit
), so I've developed a habit of just always typing-p
. This got me a surprising failure when runningI 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 howcargo install
needs both a git url and a crate name).I've ran
--help
to check what-p
does, and the discrepancy betweenDEP_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)
The text was updated successfully, but these errors were encountered: