6 个版本
0.3.0 | 2024 年 2 月 1 日 |
---|---|
0.2.1 | 2020 年 9 月 9 日 |
0.1.3 | 2020 年 9 月 3 日 |
在 Cargo 插件 中排名第 112
每月下载 40 次
38KB
584 行
检查来自 clearlydefined.io 的依赖数据
这是对 cargo
的小扩展,用于检查您的依赖树与 clearlydefined.io 的数据库。
ClearlyDefined 和我们的母组织——开源倡议组织——致力于通过明确定义来帮助开源项目蓬勃发展。
安装
cargo install cargo-clearlydefined
使用方法
在您要检查的项目中,执行以下命令
cargo clearlydefined
这将获取依赖项元数据,并打印出依赖项报告。
获取帮助
要获取一些命令行帮助,运行
cargo clearlydefined --help
它应该打印出
cargo-clearlydefined 0.2.1
USAGE:
cargo clearlydefined [OPTIONS]
OPTIONS:
-i, --input <input> Override the location of the input file (`Cargo.lock`)
-v, --verbose Verbose mode, repeat to increase verbosity
-s, --score <score> The score required to pass the test [default: 80]
-t, --score-type <score-type> Which score to test [default: effective] [possible values: Effective,
Licensed]
-f, --failed Show only failed dependencies
-x, --exclude <exclude>... List the dependencies to exclude completely
-n, --ignore <ignore>... List the dependencies to ignore when testing
-o, --output-format <output-format> Output format [default: text] [possible values: Text, CSV, Markdown]
-l, --link Add a link to clearly defined
-q, --quiet Don't show any results
--lax Lax parsing of SPDX expressions
--approve-all Approve all licenses
--approve-osi Pass if a dependency has at least one OSI approved license
-L, --approve <approved-licenses>... Pass if a dependency has at least one of the approved licenses (can be used
multiple times)
-h, --help Prints help information
-V, --version Prints version information
设置目标分数
默认目标分数是 80,但您可以更改它
cargo clearlydefined --score 50
也可以将分数降低到 0
,这将有效地禁用此测试。
要测试的分数类型
ClearlyDefined 提供不同类型的分数。默认情况下,工具将检查“有效”或“总体”分数。
您可以使用 -t
来选择要测试的分数。测试“许可分数”需要
cargo clearlydefined --score 50 -t licensed
添加链接
还可以提供 --link
参数,这将向 clearlydefined.io 的定义页面添加链接。不过,并非所有输出格式都支持此功能。
cargo clearlydefined --link
忽略和排除
您可以完全排除依赖项的处理
cargo clearlydefined -x my-test
或者简单地从目标分数测试中忽略它
cargo clearlydefined -n my-test
例如
$ cargo clearlydefined -n my-test
+------------------------------+---------+------------------------+---------+-------+
| Name | Version | Declared license | License | Score |
+------------------------------+---------+------------------------+---------+-------+
| ansi_term | 0.12.1 | MIT | ❌ | ✅ 88 |
| atty | 0.2.14 | MIT | ❌ | ✅ 88 |
| colored_json | 2.1.0 | EPL-2.0 | ❌ | ✅ 87 |
| hermit-abi | 0.1.15 | Apache-2.0 AND MIT | ❌ | ❌ 52 |
| itoa | 0.4.6 | Apache-2.0 AND MIT | ❌ | ✅ 87 |
| libc | 0.2.76 | Apache-2.0 AND MIT | ❌ | ✅ 87 |
| my-test | 0.1.0 | | 🙈 | 🙈 0 |
| ryu | 1.0.5 | Apache-2.0 AND BSL-1.0 | ❌ | ✅ 80 |
| serde | 1.0.115 | Apache-2.0 AND MIT | ❌ | ✅ 87 |
| serde_json | 1.0.57 | Apache-2.0 AND MIT | ❌ | ✅ 87 |
| winapi | 0.3.9 | Apache-2.0 AND MIT | ❌ | ✅ 87 |
| winapi-i686-pc-windows-gnu | 0.4.0 | MIT OR Apache-2.0 | ❌ | ❌ 37 |
| winapi-x86_64-pc-windows-gnu | 0.4.0 | MIT OR Apache-2.0 | ❌ | ❌ 37 |
+------------------------------+---------+------------------------+---------+-------+
SPDX 解析
工具将解析来自 clearlydefined 的 SPDX 表达式。不幸的是,一些依赖项具有无效的(根据 SPDX 规范)表达式。
您可以使用 --lax
选项,切换到对 SPDX 表达式更宽松的解析器。但是,在某些情况下,这仍然不够。目前唯一的选择是忽略或排除此类依赖项。
许可测试
如果依赖项具有有效的 SPDX 许可定义,则可以进行测试。如果没有,则基于许可的所有检查都将为此依赖项失败。
默认情况下,禁用了所有许可测试。
在大多数情况下,您正在检查的模块没有注册,定义不明确,因此无法通过许可测试。如果这是问题所在,那么您可以使用 -x
开关排除该模块。
测试依赖项是否具有 OSI 认可的许可
使用选项 --require-osi-approved
,您需要每个依赖项至少有一个 OSI 认可的许可。
检查提供的列表
您也可以提供一个接受的许可列表,工具将检查这些许可
cargo clearlydefined -L EPL-2.0 -L MIT
输出格式
默认输出格式是 "text",但您还有其他选项
CSV
为了获得逗号分隔的输出
cargo clearlydefined -o csv
示例输出
$ cargo clearlydefined --approve-osi -o csv
Name,Version,Declared license,License,Score,Score check
ansi_term,0.12.1,MIT,+,88,+
atty,0.2.14,MIT,+,88,+
colored_json,2.1.0,EPL-2.0,+,87,+
hermit-abi,0.1.15,Apache-2.0 AND MIT,+,52,-
itoa,0.4.6,Apache-2.0 AND MIT,+,87,+
libc,0.2.76,Apache-2.0 AND MIT,+,87,+
my-test,0.1.0,,-,0,-
ryu,1.0.5,Apache-2.0 AND BSL-1.0,+,80,+
serde,1.0.115,Apache-2.0 AND MIT,+,87,+
serde_json,1.0.57,Apache-2.0 AND MIT,+,87,+
winapi,0.3.9,Apache-2.0 AND MIT,+,87,+
winapi-i686-pc-windows-gnu,0.4.0,MIT OR Apache-2.0,+,37,-
winapi-x86_64-pc-windows-gnu,0.4.0,MIT OR Apache-2.0,+,37,-
Markdown
要获得漂亮的 markdown 结果,使用
cargo clearlydefined -o markdown
这将创建一个 markdown 表格,包括徽章,显示测试结果,如果您选择显示所有依赖项。
示例输出
名称 | 版本 | 声明的许可 | 许可 | 得分 |
---|---|---|---|---|
ansi_term | 0.12.1 | MIT | ✅ | ✅ 88 |
atty | 0.2.14 | MIT | ✅ | ✅ 88 |
colored_json | 2.1.0 | EPL-2.0 | ✅ | ✅ 87 |
hermit-abi | 0.1.15 | Apache-2.0 AND MIT | ✅ | ❌ 52 |
itoa | 0.4.6 | Apache-2.0 AND MIT | ✅ | ✅ 87 |
libc | 0.2.76 | Apache-2.0 AND MIT | ✅ | ✅ 87 |
my-test | 0.1.0 | ❌ | ❌ 0 | |
ryu | 1.0.5 | Apache-2.0 AND BSL-1.0 | ✅ | ✅ 80 |
serde | 1.0.115 | Apache-2.0 AND MIT | ✅ | ✅ 87 |
serde_json | 1.0.57 | Apache-2.0 AND MIT | ✅ | ✅ 87 |
winapi | 0.3.9 | Apache-2.0 AND MIT | ✅ | ✅ 87 |
winapi-i686-pc-windows-gnu | 0.4.0 | MIT OR Apache-2.0 | ✅ | ❌ 37 |
winapi-x86_64-pc-windows-gnu | 0.4.0 | MIT OR Apache-2.0 | ✅ | ❌ 37 |
使用 --link
选项
文本
当然,还有纯文本。默认
$ cargo clearlydefined --approve-osi -o text
+------------------------------+---------+------------------------+---------+-------+
| Name | Version | Declared license | License | Score |
+------------------------------+---------+------------------------+---------+-------+
| ansi_term | 0.12.1 | MIT | ✅ | ✅ 88 |
| atty | 0.2.14 | MIT | ✅ | ✅ 88 |
| colored_json | 2.1.0 | EPL-2.0 | ✅ | ✅ 87 |
| hermit-abi | 0.1.15 | Apache-2.0 AND MIT | ✅ | ❌ 52 |
| itoa | 0.4.6 | Apache-2.0 AND MIT | ✅ | ✅ 87 |
| libc | 0.2.76 | Apache-2.0 AND MIT | ✅ | ✅ 87 |
| my-test | 0.1.0 | | ❌ | ❌ 0 |
| ryu | 1.0.5 | Apache-2.0 AND BSL-1.0 | ✅ | ✅ 80 |
| serde | 1.0.115 | Apache-2.0 AND MIT | ✅ | ✅ 87 |
| serde_json | 1.0.57 | Apache-2.0 AND MIT | ✅ | ✅ 87 |
| winapi | 0.3.9 | Apache-2.0 AND MIT | ✅ | ✅ 87 |
| winapi-i686-pc-windows-gnu | 0.4.0 | MIT OR Apache-2.0 | ✅ | ❌ 37 |
| winapi-x86_64-pc-windows-gnu | 0.4.0 | MIT OR Apache-2.0 | ✅ | ❌ 37 |
+------------------------------+---------+------------------------+---------+-------+
依赖项
~11–23MB
~331K SLoC