55 个版本

0.3.6 2024 年 8 月 7 日
0.3.5 2024 年 7 月 17 日
0.3.2 2024 年 5 月 28 日
0.3.1 2024 年 1 月 24 日
0.2.10 2020 年 6 月 16 日

#32Cargo 插件

Download history 499/week @ 2024-05-02 445/week @ 2024-05-09 444/week @ 2024-05-16 563/week @ 2024-05-23 547/week @ 2024-05-30 536/week @ 2024-06-06 470/week @ 2024-06-13 307/week @ 2024-06-20 438/week @ 2024-06-27 460/week @ 2024-07-04 827/week @ 2024-07-11 590/week @ 2024-07-18 448/week @ 2024-07-25 478/week @ 2024-08-01 735/week @ 2024-08-08 525/week @ 2024-08-15

2,276 每月下载量

MIT 许可证

145KB
3.5K SLoC

cargo-workspaces

灵感来自 Lerna

一个通过提供版本、发布、执行命令等实用工具,优化围绕 cargo 工作区的 git 和 cargo 工作流程的工具。

我创建这个工具是为了在 clap 和其他依赖工作区项目上工作。但这也适用于单个包,因为默认情况下每个单独的包都是一个工作区。

  1. 安装
  2. 用法
    1. 初始化
    2. 创建
    3. 列出
    4. 更改
    5. 执行
    6. 版本
      1. 固定或独立
    7. 发布
    8. 重命名
    9. 计划
  3. 配置
  4. 变更日志

安装

cargo install cargo-workspaces

用法

安装的工具可以通过 cargo workspacescargo ws 调用。这两个都指向同一个命令。

您可以使用 cargo ws helpcargo ws help <子命令> 在任何时间了解允许的选项。

此工具提供的基本命令如下。假设您在 cargo 工作区内部运行它们。

初始化

在给定目录中初始化一个新的 cargo 工作区。如果不存在则创建 Cargo.toml,并将 members 填充为在该目录中可以找到的所有包。

USAGE:
    cargo workspaces init [PATH]

ARGS:
    <PATH>    Path to the workspace root [default: .]

OPTIONS:
    -h, --help    Print help information

创建

交互式地在工作区中创建新的crate。我们建议使用此方法而不是cargo new。由于版本负责确定版本,因此所有crate都以0.0.0版本开始。

USAGE:
    cargo workspaces create [OPTIONS] <PATH>

ARGS:
    <PATH>    Path for the crate relative to the workspace manifest

OPTIONS:
        --bin                  Whether this is a binary crate
        --edition <EDITION>    The crate edition [possible values: 2015, 2018, 2021]
    -h, --help                 Print help information
        --lib                  Whether this is a library crate
        --name <NAME>          The name of the crate

列出

列出工作区中的crate。

USAGE:
    cargo workspaces list [OPTIONS]

OPTIONS:
    -h, --help    Print help information

LIST OPTIONS:
    -a, --all     Show private crates that are normally hidden
        --json    Show information as a JSON array
    -l, --long    Show extended information

提供多个别名。

  • cargo ws ls等同于cargo ws list
  • cargo ws ll等同于cargo ws list --long
  • cargo ws la等同于cargo ws list --all

更改

列出自上次git标签以来已更改的crate。这对于查看将是下一个版本发布命令主题的crate列表很有用。

USAGE:
    cargo workspaces changed [OPTIONS]

OPTIONS:
        --error-on-empty              Return non-zero exit code if no changes detected
        --force <pattern>             Always include targeted crates matched by glob even when there are no changes
    -h, --help                        Print help information
        --ignore-changes <pattern>    Ignore changes in files matched by glob
        --include-merged-tags         Include tags from merged branches
        --since <SINCE>               Use this git reference instead of the last tag

LIST OPTIONS:
    -a, --all     Show private crates that are normally hidden
        --json    Show information as a JSON array
    -l, --long    Show extended information

执行

在工作区的每个crate中执行任意命令。

USAGE:
    cargo workspaces exec [OPTIONS] <ARGS>...

ARGS:
    <ARGS>...

OPTIONS:
    -h, --help                Print help information
        --ignore <pattern>    Ignore the crates matched by glob
        --ignore-private      Ignore private crates
        --no-bail             Continue executing command despite non-zero exit in a given crate

例如,如果您想在每个crate中运行ls -l,您可以简单地这样做cargo ws exec ls -l

版本

增加工作区中crate的版本。此命令执行以下操作

  1. 确定自上次标记版本以来已更新的crate
  2. 根据crate提示新版本
  3. 修改crate清单以反映新版本
  4. 如有必要,更新工作区间依赖项版本约束
  5. 提交这些更改
  6. 标记提交
  7. 推送到git远程仓库

您可以使用此命令的标志和选项影响上述步骤。

USAGE:
    cargo workspaces version [OPTIONS] [ARGS]

OPTIONS:
    -h, --help    Print help information

VERSION ARGS:
    <BUMP>      Increment all versions by the given explicit semver keyword while skipping the prompts for them
                [possible values: major, minor, patch, premajor, preminor, prepatch, skip, prerelease, custom]
    <CUSTOM>    Specify custom version value when 'bump' is set to 'custom'

VERSION OPTIONS:
    -a, --all                         Also do versioning for private crates (will not be published)
        --exact                       Specify inter dependency version numbers exactly with `=`
        --force <pattern>             Always include targeted crates matched by glob even when there are no changes
        --ignore-changes <pattern>    Ignore changes in files matched by glob
        --include-merged-tags         Include tags from merged branches
        --pre-id <identifier>         Specify prerelease identifier
    -y, --yes                         Skip confirmation prompt

GIT OPTIONS:
        --allow-branch <pattern>            Specify which branches to allow from [default: master]
        --amend                             Amend the existing commit, instead of generating a new one
        --git-remote <remote>               Push git changes to the specified remote [default: origin]
        --individual-tag-prefix <prefix>    Customize prefix for individual tags (should contain `%n`) [default: %n@]
    -m, --message <MESSAGE>                 Use a custom commit message when creating the version commit [default: Release %v]
        --no-git-commit                     Do not commit version changes
        --no-git-push                       Do not push generated commit and tags to git remote
        --no-git-tag                        Do not tag generated commit
        --no-global-tag                     Do not create a global tag for a workspace
        --no-individual-tags                Do not tag individual versions for crates
        --tag-prefix <prefix>               Customize tag prefix (can be empty) [default: v]

固定或独立

默认情况下,工作区中的所有crate将共享单个版本。但是,如果您想使crate的版本独立于其他crate,则可以将以下内容添加到该crate

[package.metadata.workspaces]
independent = true

有关更多详细信息,请参阅下面的配置部分。

发布

根据依赖关系以正确顺序发布工作区中的所有crate。默认情况下,此命令首先运行版本。如果您不希望这样做,则可以提供--from-git选项。

注意:在构建用于确定正确发布顺序的依赖关系图时,不考虑dev依赖项。这是因为dev依赖项由cargo publish忽略 - 因此,具有path属性的本地crate(dev依赖项)不应有version字段。

USAGE:
    cargo workspaces publish [OPTIONS] [ARGS]

OPTIONS:
    -h, --help    Print help information

VERSION ARGS:
    <BUMP>      Increment all versions by the given explicit semver keyword while skipping the prompts for them
                [possible values: major, minor, patch, premajor, preminor, prepatch, skip, prerelease, custom]
    <CUSTOM>    Specify custom version value when 'bump' is set to 'custom'

VERSION OPTIONS:
    -a, --all                         Also do versioning for private crates (will not be published)
        --exact                       Specify inter dependency version numbers exactly with `=`
        --force <pattern>             Always include targeted crates matched by glob even when there are no changes
        --ignore-changes <pattern>    Ignore changes in files matched by glob
        --include-merged-tags         Include tags from merged branches
        --pre-id <identifier>         Specify prerelease identifier
    -y, --yes                         Skip confirmation prompt

GIT OPTIONS:
        --allow-branch <pattern>            Specify which branches to allow from [default: master]
        --amend                             Amend the existing commit, instead of generating a new one
        --git-remote <remote>               Push git changes to the specified remote [default: origin]
        --individual-tag-prefix <prefix>    Customize prefix for individual tags (should contain `%n`) [default: %n@]
    -m, --message <MESSAGE>                 Use a custom commit message when creating the version commit [default: Release %v]
        --no-git-commit                     Do not commit version changes
        --no-git-push                       Do not push generated commit and tags to git remote
        --no-git-tag                        Do not tag generated commit
        --no-global-tag                     Do not create a global tag for a workspace
        --no-individual-tags                Do not tag individual versions for crates
        --tag-prefix <prefix>               Customize tag prefix (can be empty) [default: v]

PUBLISH OPTIONS:
        --allow-dirty            Allow dirty working directories to be published
        --dry-run                Runs in dry-run mode
        --no-remove-dev-deps     Don't remove dev-dependencies while publishing
        --no-verify              Skip crate verification (not recommended)
        --publish-as-is          Publish crates from the current commit without versioning

REGISTRY OPTIONS:
        --registry <REGISTRY>    The Cargo registry to use
        --token <TOKEN>          The token to use for accessing the registry

重命名

重命名项目中的crate。当您可能想要使用标准前缀发布crate时,可以运行此命令。

USAGE:
    cargo workspaces rename [OPTIONS] <TO>

ARGS:
    <TO>    The value that should be used as new name (should contain `%n`)

OPTIONS:
    -a, --all                 Rename private crates too
    -f, --from <crate>        Rename only a specific crate
    -h, --help                Print help information
        --ignore <pattern>    Ignore the crates matched by glob

计划

列出发布顺序中的crate。这不会检查更改或尝试版本。它按原样接受crate。

USAGE:
    cargo workspaces plan [OPTIONS]

OPTIONS:
    -h, --help              Print help information
        --skip-published    Skip already published crate versions

REGISTRY OPTIONS:
        --registry <REGISTRY>    The Cargo registry to use
        --token <TOKEN>          The token to use for accessing the registry

LIST OPTIONS:
        --json    Show information as a JSON array
    -l, --long    Show extended information

配置

有两种类型的选项。

  • 工作区:在 [workspace.metadata.workspaces] 中指定的工作区选项
  • :在 [package.metadata.workspaces] 中指定的包选项

如果选项可以在两个地方存在,这意味着在 中指定的值会覆盖在 工作区 中指定的值。

名称 类型 工作区 用于命令
allow_branch 字符串 versionpublish
independent 布尔值 versionpublish
no_individual_tags 布尔值 versionpublish

贡献者

以下是一个贡献者列表

待办事项

变更日志

请参阅CHANGELOG.md

许可协议

MIT/X11

错误报告

在此报告

创建者

Pavan Kumar Sunkara ([email protected])

githubtwitter 上关注我

依赖项

~24–40MB
~687K SLoC