This tool extends Cargo to allow you to add, remove, and upgrade dependencies by modifying your Cargo.toml
file from the command line.
Currently available subcommands:
Thanks for your interest - we gratefully welcome contributions.
Questions can be asked in issues, or on Gitter.
To help us help you get pull requests merged quickly and smoothly, open an issue before submitted large changes. Please keep the contents of pull requests and commits short. Commit messages should include the intent of the commit.
cargo-edit
has a moderately comprehensive test suite. Contributions that add/improve tests are awesome. Please add tests for every change.
cargo-edit
uses rustfmt-nightly
for formatting and clippy
for linting.
sh
$ cargo install cargo-edit
(Please check cargo
's documentation to learn how cargo install
works and how to set up your system so it finds binaries installed by cargo
.)
Install a sub-set of the commands with cargo install -f --no-default-features --features "<COMMANDS>"
, where <COMMANDS>
is a space-separated list of commands; i.e. add rm upgrade
for the full set.
cargo add
Add new dependencies to your Cargo.toml
. When no version is specified, cargo add
will try to query the latest version's number from crates.io.
sh
$ # Add a specific version
$ cargo add regex@0.1.41 --dev
$ # Query the latest version from crates.io and adds it as build dependency
$ cargo add gcc --build
$ # Add a non-crates.io crate
$ cargo add local_experiment --path=lib/trial-and-error/
$ # Also
$ cargo add lib/trial-and-error/
```plain
$ cargo add --help
Usage:
cargo add
Specify what crate to add:
--vers cargo add bitflags@0.3.2
.
--git
Specify where to add the crate:
-D --dev Add crate as development dependency.
-B --build Add crate as build dependency.
--optional Add as an optional dependency (for use in features). This does not work
for dev-dependencies
or build-dependencies
.
--target dev-dependencies
or build-dependencies
.
Options:
--upgrade=~
modifier), "minor"
(^
modifier, default), or "all" (>=
).
--manifest-path=
This command allows you to add a dependency to a Cargo.toml manifest file. If cargo add
will try to automatically get the crate name
and set the appropriate --git
or --path
value.
Please note that Cargo treats versions like "1.2.3" as "^1.2.3" (and that "^1.2.3" is specified
as ">=1.2.3 and <2.0.0"). By default, cargo add
will use this format, as it is the one that the
crates.io registry suggests. One goal of cargo add
is to prevent you from using wildcard
dependencies (version set to "*").
```
cargo rm
Remove dependencies from your Cargo.toml
.
sh
$ cargo rm regex
$ cargo rm regex --dev
$ cargo rm regex --build
```plain
$ cargo rm --help
Usage:
cargo rm
Options:
-D --dev Remove crate as development dependency.
-B --build Remove crate as build dependency.
--manifest-path=
Remove a dependency from a Cargo.toml manifest file. ```
cargo upgrade
Upgrade dependencies in your Cargo.toml
to their latest versions.
```sh
$ cargo upgrade
$ cargo upgrade -d libc --dependency serde ```
```plain Upgrade all dependencies in a manifest file to the latest version.
Usage:
cargo upgrade [--all] [--dependency
Options:
--all Upgrade all packages in the workspace.
-d --dependency
Dev, build, and all target dependencies will also be upgraded. Only dependencies from crates.io are supported. Git/path dependencies will be ignored.
All packages in the workspace will be upgraded if the --all
flag is supplied. The --all
flag may
be supplied in the presence of a virtual manifest.
```
Apache-2.0/MIT