Skip to content

Commit 696d256

Browse files
authored
docs: include license checking page (#860)
1 parent bf76412 commit 696d256

File tree

3 files changed

+132
-5
lines changed

3 files changed

+132
-5
lines changed

lib/src/commands/packages/commands/check/commands/licenses.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ const pubspecLockBasename = 'pubspec.lock';
1818
Uri pubLicenseUri(String packageName) =>
1919
Uri.parse('https://pub.dev/packages/$packageName/license');
2020

21+
/// The URI for the very_good_cli license documentation page.
22+
@visibleForTesting
23+
final licenseDocumentationUri = Uri.parse(
24+
'https://cli.vgv.dev/docs/commands/check_licenses',
25+
);
26+
2127
/// Defines a [Map] with dependencies as keys and their licenses as values.
2228
///
2329
/// If a dependency's license failed to be retrieved its license will be `null`.
@@ -111,8 +117,12 @@ class PackagesCheckLicensesCommand extends Command<int> {
111117
...forbiddenLicenses,
112118
]);
113119
if (invalidLicenses.isNotEmpty) {
120+
final documentationLink = link(
121+
uri: licenseDocumentationUri,
122+
message: 'documentation',
123+
);
114124
_logger.warn(
115-
'''Some licenses failed to be recognized: ${invalidLicenses.stringify()}. Refer to the documentation for a list of valid licenses.''',
125+
'''Some licenses failed to be recognized: ${invalidLicenses.stringify()}. Refer to the $documentationLink for a list of valid licenses.''',
116126
);
117127
}
118128

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
---
2+
sidebar_position: 3
3+
---
4+
5+
# Check licenses 👨‍⚖️
6+
7+
Very Good CLI offers a simple and straightforward license checker for dependencies hosted by [Dart's package manager][pub]. Allowing developers to easily keep track of the rights and restrictions external dependencies might impose on their projects.
8+
9+
## Quick Start 🚀
10+
11+
To get started, install [Very Good CLI](https://cli.vgv.dev/docs/overview#quick-start-) and run the following command within your Dart or Flutter project:
12+
13+
```sh
14+
very_good packages check licenses
15+
```
16+
17+
:::info
18+
The license checker requires an internet connection to fetch the data from [Dart's package manager][pub].
19+
:::
20+
21+
## Arguments ⚙️
22+
23+
### `allowed`
24+
25+
Only allows the use of certain licenses. The command will exit with an error and log the list of all the dependencies that have an unlisted license.
26+
27+
#### Example usage:
28+
29+
```sh
30+
very_good packages check licenses --allowed=MIT,BSD-3-Clause
31+
32+
# ✓ Retrieved 6 licenses from 6 packages of type: BSD-3-Clause (3), MIT (1), unknown (1) and Apache-2.0 (1).
33+
# 2 dependencies have banned licenses: html (unknown) and universal_io (Apache-2.0).
34+
```
35+
36+
:::info
37+
A comprehensive list of all the licenses allowed as options is available within the [_Supported licenses_](#supported-licenses-💳) section of this document.
38+
:::
39+
40+
### `forbidden`
41+
42+
Deny the use of certain licenses. The command will exit with an error and log the list of all the dependencies that have a blocked license.
43+
44+
#### Example usage:
45+
46+
```sh
47+
very_good packages check licenses --forbidden=unknown,Apache-2.0
48+
49+
# ✓ Retrieved 6 licenses from 6 packages of type: BSD-3-Clause (3), MIT (1), unknown (1) and Apache-2.0 (1).
50+
# 2 dependencies have banned licenses: html (unknown) and universal_io (Apache-2.0).
51+
```
52+
53+
:::warning
54+
The `allowed` and `forbidden` options can't be used at the same time. Typical organization usage dictates which licenses are allowed or forbidden, hence optimizing for that use case.
55+
:::
56+
57+
### `dependency-type`
58+
59+
The type of dependencies to check licenses for. There are three available types:
60+
61+
- [`direct-dev`](https://dart.dev/tools/pub/dependencies#dev-dependencies): Another package that your package needs during development.
62+
- [`direct-main`](https://dart.dev/tools/pub/dependencies): Another package that your package needs to work.
63+
- [`transitive`](https://dart.dev/tools/pub/glossary#transitive-dependency): A dependency that your package indirectly uses because one of its dependencies requires it.
64+
65+
When unspecified, it defaults to `direct-main`.
66+
67+
#### Example usage:
68+
69+
```sh
70+
very_good packages check licenses --dependency-type=direct-main,transitive
71+
72+
# ✓ Retrieved 83 licenses from 82 packages of type: BSD-3-Clause (65), MIT (15), unknown (1), BSD-2-Clause (1) and Apache-2.0 (1).
73+
```
74+
75+
:::info
76+
The license checker only requires a [lockfile](https://dart.dev/tools/pub/glossary#lockfile) to gather dependencies. The lockfile is generated automatically for you by [pub][pub] when you run `pub get`, `pub upgrade`, or `pub downgrade`.
77+
:::
78+
79+
### `skip-packages`
80+
81+
Skips packages from having their licenses checked. Skipped packages will not be checked against `allowed` or `forbidden` licenses.
82+
83+
#### Example usage:
84+
85+
```sh
86+
very_good packages check licenses --skip-packages=html,universal_io
87+
88+
# ✓ Retrieved 4 licenses from 4 packages of type: BSD-3-Clause (3) and MIT (1).
89+
```
90+
91+
### `ignore-retrieval-failures`
92+
93+
Disregard licenses that failed to be retrieved. Avoids terminating if the license of a dependency could not be retrieved; this may happen if something went wrong when fetching information from [pub][pub].
94+
95+
#### Example usage:
96+
97+
```sh
98+
very_good packages check licenses --ignore-retrieval-failures
99+
100+
# ✓ Retrieved 6 licenses from 6 packages of type: BSD-3-Clause (3), MIT (1), unknown (1) and Apache-2.0 (1).
101+
```
102+
103+
## Supported licenses 💳
104+
105+
The license detection is processed by [Dart's package analyzer](https://pub.dev/packages/pana), which reports commonly found licenses (SPDX licenses). The list of accepted licenses can be seen in the [SPDX GitHub repository](https://github.com/spdx/license-list-data/tree/main/text) or in the [SPDX License enumeration](https://github.com/VeryGoodOpenSource/very_good_cli/blob/main/lib/src/pub_license/spdx_license.gen.dart). Therefore, when specifying a license within arguments it must strictly match with the SPDX license name.
106+
107+
If a license file is incorrectly formatted or is not a commonly found license, then it might be reported as `unknown`. If the former is true, we suggest notifying the package maintainer about the issue.
108+
109+
[pub]: https://pub.dev/

test/src/commands/packages/commands/check/commands/licenses_test.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -661,8 +661,12 @@ void main() {
661661
],
662662
);
663663

664-
const warningMessage =
665-
'''Some licenses failed to be recognized: $invalidLicense. Refer to the documentation for a list of valid licenses.''';
664+
final documentationLink = link(
665+
uri: licenseDocumentationUri,
666+
message: 'documentation',
667+
);
668+
final warningMessage =
669+
'''Some licenses failed to be recognized: $invalidLicense. Refer to the $documentationLink for a list of valid licenses.''';
666670
verify(
667671
() => logger.warn(warningMessage),
668672
).called(1);
@@ -813,8 +817,12 @@ void main() {
813817
],
814818
);
815819

816-
const warningMessage =
817-
'''Some licenses failed to be recognized: $invalidLicense. Refer to the documentation for a list of valid licenses.''';
820+
final documentationLink = link(
821+
uri: licenseDocumentationUri,
822+
message: 'documentation',
823+
);
824+
final warningMessage =
825+
'''Some licenses failed to be recognized: $invalidLicense. Refer to the $documentationLink for a list of valid licenses.''';
818826
verify(
819827
() => logger.warn(warningMessage),
820828
).called(1);

0 commit comments

Comments
 (0)