-
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
Subcommand to add a new dependency to Cargo.toml #2179
Comments
Good to see others think it's useful to have too. Judging by the long list of dependencies of cargo-edit it looks like it reimplements cargo's code for communicating with the registry, so the implementation would be much smaller if it were built into cargo. |
This is a dupe of the #4, which was in fact closed pointing to |
Knowing about existence of cargo-edit is a barrier. For me it went like this: $ cargo install package
…
specified package has no binaries …grumble, grumble, advised to use cargo-edit… $ cargo install cargo-edit
…
# long list of compiled deps here
…
$ cargo add package
No such subcommand
Did you mean `doc`?
$ export PATH=$PATH:~/.cargo/bin
$ cargo add package That's not a great experience. Having it listed in |
You are kidding me. An official package manager bug about not being able to add a dependency via its cli is closed because some other tool out there can do this. Sic. |
For anyone else confused about the actual answer, first:
after that, you can:
etc. |
@tom-james-watson thanks for the awesome explanation but I still don't see why cargo-edit is not install by default. |
There's an intent to. It's now being tracked in #5586 and there's a WIP PR against that too. |
just hit my head against this, while trying to make my first step in rust. SUPER frustrating |
Also, installing cargo-edit was a whopping 239 crates for me, which takes quite a while to download and install. Definitely not a great user experience. |
Moderator note: Please don't post off topic and unconstructive rants about other software ecosystems in official Rust spaces. |
But this is constructive. It's a good example. |
I believe @BurntSushi refers to a comment that was deleted |
Indeed. I'm leaving my comment as a reminder. :) |
Is there a specific reason for the Different hands working on each or some other more specific reason? |
I suspect there's a good reason. Perhaps someone could link a blog or something explaining this design decision? |
I was surprised by this too. Coming from node having a command that does "add this package and save it in the list of dependencies" should be available out of the gate. I mean, 90% of the time I install something I'm going to be using it as part of my project, so why not save it and save me the trouble of editing the file? |
It's being worked on: #5586 |
"just hit my head against this, while trying to make my first step in rust. SUPER frustrating"++; |
Until #5586, getting cargo install cargo-edit One more great thing about it is you don't have to reinstall it for every toolchain update. You can do it after installing Finding out it exists is the bigger deal. I understand the unwillingness to add it to documentation (eg to the error text when the subcommand is exactly |
@qm3ster on top of that, |
It really matters whether it's built-in or something that needs to be installed. For years now, I've pushed for use of |
@kornelski I'm curious is it possible to install |
This is now tracked in #5586 |
I can't believe I had to find this github issue in order to learn how to add dependencies from the terminal. :P Please add the ability to add dependencies from crates.io to cargo, not involving having to learn that cargo-edit is a thing! |
For anyone on this thread that didn't switch over to the issue posted above (#5586), cargo-add has been merged. It will take several months for it to go from the nightly to beta and then stable release channels. |
I've grown to appreciate
which automatically finds the package and adds it to
package.json
.composer require
works in a similar way.Cargo isn't as convenient for adding new dependencies to a project. I need to:
That's a bit tedious, especially that I have to switch from terminal to a web browser.
I'd be much nicer if Cargo had a command for adding dependencies, e.g.
that would find the package on crates.io and add it with an appropriate version to
[dependencies]
in Cargo.toml.edit: for now, the fix is to run
cargo install cargo-edit
that addscargo add
commandThe text was updated successfully, but these errors were encountered: