#cargo-toml #cargo #cargo-command #cargo-subcommand #最新版本 #crates #bump-version

bin+lib cargo-edit-9

此插件扩展了 Cargo,允许您通过修改命令行中的 Cargo.toml 文件来添加和删除依赖。它包含 cargo addcargo rmcargo upgrade

2 个版本

0.9.3 2023年3月20日
0.9.2 2023年3月20日

#327 in Cargo 插件

Download history 42/week @ 2024-03-13 52/week @ 2024-03-20 31/week @ 2024-03-27 47/week @ 2024-04-03 15/week @ 2024-04-10 51/week @ 2024-04-17 31/week @ 2024-04-24 26/week @ 2024-05-01 11/week @ 2024-05-08 19/week @ 2024-05-15 16/week @ 2024-05-22 12/week @ 2024-05-29 31/week @ 2024-06-05 36/week @ 2024-06-12 78/week @ 2024-06-19 80/week @ 2024-06-26

230 次月下载
用于 rustsec-with-git2-v16

Apache-2.0 OR MIT

185KB
4K SLoC

cargo edit

Build Status Build Status Build status Coverage Status crates.io Join the chat at https://gitter.im/cargo-edit/Lobby

此工具扩展了 Cargo,允许您通过修改命令行中的 Cargo.toml 文件来添加、删除和升级依赖。

当前可用的子命令

分叉版本

这是一个为了 API 兼容性原因而回滚到 cargo-edit 0.9 的 git2 版本。

参见:https://github.com/killercup/cargo-edit/issues/837

原始和当前仓库可在此找到:killercurp/cargo-edit

从长远来看,这个依赖项预计将消失并合并到 cargo 中。

贡献

感谢您的兴趣 - 我们非常欢迎贡献。

可以在 问题 中提问,或在 Gitter 上提问。

为了帮助我们更快更顺利地合并拉取请求,在提交大改动之前请先打开一个issue。请确保拉取请求和提交的内容简短。提交信息应包含提交的意图。

cargo-edit 拥有一个相对完整的测试套件。添加/改进测试的贡献非常棒。请为每次更改添加测试。

cargo-edit 使用 rustfmt 进行格式化和 clippy 进行代码风格检查。

安装

Packaging status

请确保您已安装了较新版本的rust/cargo。在Ubuntu上,您还需要安装 libssl-devpkg-config 软件包。

$ cargo install cargo-edit

如果您想使用捆绑的 openssl

$ cargo install cargo-edit --features vendored-openssl

编译器支持:需要 rustc 1.44+

(请查阅 cargo 的文档 了解 cargo install 的工作原理以及如何设置您的系统以便找到由 cargo 安装的二进制文件。)

使用 cargo install -f --no-default-features --features "<COMMANDS>" 安装命令子集,其中 <COMMANDS> 是以空格分隔的命令列表;例如,完整的命令集为 add rm upgrade

可用子命令

cargoadd

将新的依赖项添加到您的 Cargo.toml 中。如果没有指定版本,cargo add 将尝试从 crates.io 查询最新版本的编号。

示例

$ # Add a specific version
$ cargo add [email protected] --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/
$ # Add a non-crates.io crate; the crate name will be found automatically
$ cargo add lib/trial-and-error/
$ # Add a crates.io crate with a local development path
$ cargo add my_helper --vers=1.3.1 --path=lib/my-helper/
$ # Add a renamed dependency
$ cargo add thiserror --rename error

用法

$ cargo-add add -h
cargo-add [..]
Add dependencies to a Cargo.toml manifest file

USAGE:
    cargo add [OPTIONS] <DEP>[@<VERSION>] [+<FEATURE>,...] ...
    cargo add [OPTIONS] <DEP_PATH> [+<FEATURE>,...] ...

ARGS:
    <DEP_ID>...    Reference to a package to add as a dependency

OPTIONS:
        --no-default-features     Disable the default features
        --default-features        Re-enable the default features
    -F, --features <FEATURES>     Space-separated list of features to add
        --optional                Mark the dependency as optional
        --no-optional             Mark the dependency as required
    -r, --rename <RENAME>         Rename the dependency
        --registry <REGISTRY>     Package registry for this dependency
        --manifest-path <PATH>    Path to `Cargo.toml`
    -p, --package <PKGID>         Package to modify
        --offline                 Run without accessing the network
        --dry-run                 Don't actually write the manifest
        --quiet                   Do not print any output in case of success
    -h, --help                    Print help information
    -V, --version                 Print version information

SECTION:
    -D, --dev                Add as development dependency
    -B, --build              Add as build dependency
        --target <TARGET>    Add as dependency to the given target platform

UNSTABLE:
    -Z <FLAG>                Unstable (nightly-only) flags [possible values: git, inline-add]
        --git <URI>          Git repository location
        --branch <BRANCH>    Git branch to download the crate from
        --tag <TAG>          Git tag to download the crate from
        --rev <REV>          Git reference to download the crate from

Examples:
  $ cargo add regex --build
  $ cargo add trycmd --dev
  $ cargo add ./crate/parser/
  $ cargo add serde +derive serde_json

cargorm

从您的 Cargo.toml 中删除依赖项。

示例

$ # Remove a dependency
$ cargo rm regex
$ # Remove a development dependency
$ cargo rm regex --dev
$ # Remove a build dependency
$ cargo rm regex --build

用法

$ cargo-rm rm --help
cargo-rm [..]
Remove a dependency from a Cargo.toml manifest file

USAGE:
    cargo rm [OPTIONS] <CRATE>...

ARGS:
    <CRATE>...    Crates to be removed

OPTIONS:
    -B, --build                   Remove crate as build dependency
    -D, --dev                     Remove crate as development dependency
    -h, --help                    Print help information
        --manifest-path <PATH>    Path to the manifest to remove a dependency from
    -p, --package <PKGID>         Package id of the crate to remove this dependency from
    -q, --quiet                   Do not print any output in case of success
    -V, --version                 Print version information
    -Z <FLAG>                     Unstable (nightly-only) flags

cargoupgrade

将您的 Cargo.toml 中的依赖项升级到最新版本。

要指定升级到的版本,请使用 <crate 名称>@<版本> 格式提供依赖项,例如 cargo upgrade docopt@~0.9.0 serde@>=0.9,<2.0

此命令与 cargo update 不同,后者更新本地锁定文件(Cargo.lock)中记录的依赖项版本。

示例

# Upgrade all dependencies for the current crate
$ cargo upgrade
# Upgrade docopt (to ~0.9) and serde (to >=0.9,<2.0)
$ cargo upgrade docopt@~0.9 serde@>=0.9,<2.0
# Upgrade regex (to the latest version) across all crates in the workspace
$ cargo upgrade regex --workspace
# Upgrade all dependencies except docopt and serde
$ cargo upgrade --exclude docopt serde

用法

$ cargo-upgrade upgrade --help
cargo-upgrade [..]
Upgrade dependencies as specified in the local manifest file (i.e. Cargo.toml)

USAGE:
    cargo upgrade [OPTIONS] [DEPENDENCY]...

ARGS:
    <DEPENDENCY>...    Crates to be upgraded

OPTIONS:
        --all                     [deprecated in favor of `--workspace`]
        --allow-prerelease        Include prerelease versions when fetching from crates.io (e.g.
                                  0.6.0-alpha')
        --dry-run                 Print changes to be made without making them
        --exclude <EXCLUDE>       Crates to exclude and not upgrade
    -h, --help                    Print help information
        --manifest-path <PATH>    Path to the manifest to upgrade
        --offline                 Run without accessing the network
    -p, --package <PKGID>         Package id of the crate to add this dependency to
        --skip-compatible         Only update a dependency if the new version is semver incompatible
        --to-lockfile             Upgrade all packages to the version in the lockfile
    -V, --version                 Print version information
        --workspace               Upgrade all packages in the workspace
    -Z <FLAG>                     Unstable (nightly-only) flags [possible values:
                                  preserve-precision]

This command differs from `cargo update`, which updates the dependency versions recorded in the
local lock file (Cargo.lock).

If `<dependency>`(s) are provided, only the specified dependencies will be upgraded. The version to
upgrade to for each can be specified with e.g. `[email protected]` or `serde@>=0.9,<2.0`.

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 `--workspace` flag is supplied. The
`--workspace` flag may be supplied in the presence of a virtual manifest.

If the '--to-lockfile' flag is supplied, all dependencies will be upgraded to the currently locked
version as recorded in the Cargo.lock file. This flag requires that the Cargo.lock file is
up-to-date. If the lock file is missing, or it needs to be updated, cargo-upgrade will exit with an
error. If the '--to-lockfile' flag is supplied then the network won't be accessed.

cargoset-version

设置 Cargo.toml 中的版本。

示例

# Set the version to the version 1.0.0
$ cargo set-version 1.0.0
# Bump the version to the next major
$ cargo set-version --bump major
# Bump version to the next minor
$ cargo set-version --bump minor
# Bump version to the next patch
$ cargo set-version --bump patch

用法

$ cargo-set-version set-version --help
cargo-set-version [..]
Change a package's version in the local manifest file (i.e. Cargo.toml)

USAGE:
    cargo set-version [OPTIONS] [TARGET]

ARGS:
    <TARGET>    Version to change manifests to

OPTIONS:
        --all                     [deprecated in favor of `--workspace`]
        --bump <BUMP>             Increment manifest version [possible values: major, minor, patch,
                                  release, rc, beta, alpha]
        --dry-run                 Print changes to be made without making them
        --exclude <EXCLUDE>       Crates to exclude and not modify
    -h, --help                    Print help information
    -m, --metadata <METADATA>     Specify the version metadata field (e.g. a wrapped libraries
                                  version)
        --manifest-path <PATH>    Path to the manifest to upgrade
    -p, --package <PKGID>         Package id of the crate to change the version of
    -V, --version                 Print version information
        --workspace               Modify all packages in the workspace
    -Z <FLAG>                     Unstable (nightly-only) flags

有关 metadata 的更多信息,请参阅 semver crate 的文档

许可证

Apache-2.0/MIT

依赖项

~23–36MB
~740K SLoC