Skip to content

Commit 0662587

Browse files
authored
feat: add skip-packages to check licenses (#854)
1 parent 0542b34 commit 0662587

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ class PackagesCheckLicensesCommand extends Command<int> {
6565
..addMultiOption(
6666
'forbidden',
6767
help: 'Deny the use of certain licenses.',
68+
)
69+
..addMultiOption(
70+
'skip-packages',
71+
help: 'Skip packages from having their licenses checked.',
6872
);
6973
}
7074

@@ -94,6 +98,7 @@ class PackagesCheckLicensesCommand extends Command<int> {
9498
final dependencyTypes = _argResults['dependency-type'] as List<String>;
9599
final allowedLicenses = _argResults['allowed'] as List<String>;
96100
final forbiddenLicenses = _argResults['forbidden'] as List<String>;
101+
final skippedPackages = _argResults['skip-packages'] as List<String>;
97102

98103
if (allowedLicenses.isNotEmpty && forbiddenLicenses.isNotEmpty) {
99104
usageException(
@@ -135,6 +140,8 @@ class PackagesCheckLicensesCommand extends Command<int> {
135140
final isPubHosted = dependency.hosted != null;
136141
if (!isPubHosted) return false;
137142

143+
if (skippedPackages.contains(dependency.package())) return false;
144+
138145
final dependencyType = dependency.type();
139146
return (dependencyTypes.contains('direct-main') &&
140147
dependencyType == DependencyType.direct) ||

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

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ const _expectedPackagesCheckLicensesUsage = [
2626
''' [transitive] Check for transitive dependencies.\n'''
2727
'\n'
2828
''' --allowed Only allow the use of certain licenses.\n'''
29-
''' --forbidden Deny the use of certain licenses.\n'''
29+
' --forbidden Deny the use of certain licenses.\n'
30+
''' --skip-packages Skip packages from having their licenses checked.\n'''
3031
'\n'
3132
'Run "very_good help" to see global options.'
3233
];
@@ -909,6 +910,78 @@ void main() {
909910
});
910911
});
911912

913+
group('skip-packages', () {
914+
const skipPackagesArgument = '--skip-packages';
915+
916+
group('skips', () {
917+
test(
918+
'a single package by name',
919+
withRunner(
920+
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
921+
final tempDirectory = Directory.systemTemp.createTempSync();
922+
addTearDown(() => tempDirectory.deleteSync(recursive: true));
923+
924+
File(path.join(tempDirectory.path, pubspecLockBasename))
925+
.writeAsStringSync(_validMultiplePubspecLockContent);
926+
927+
when(() => logger.progress(any())).thenReturn(progress);
928+
929+
final result = await commandRunner.run(
930+
[
931+
...commandArguments,
932+
skipPackagesArgument,
933+
'cli_completion',
934+
tempDirectory.path,
935+
],
936+
);
937+
938+
verify(
939+
() => progress.update('Collecting licenses of 0/1 packages.'),
940+
).called(1);
941+
verify(
942+
() => progress.complete(
943+
'''Retrieved 1 license from 1 package of type: MIT (1).''',
944+
),
945+
).called(1);
946+
expect(result, equals(ExitCode.success.code));
947+
}),
948+
);
949+
950+
test(
951+
'multiple packages by name',
952+
withRunner(
953+
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
954+
final tempDirectory = Directory.systemTemp.createTempSync();
955+
addTearDown(() => tempDirectory.deleteSync(recursive: true));
956+
957+
File(path.join(tempDirectory.path, pubspecLockBasename))
958+
.writeAsStringSync(_validMultiplePubspecLockContent);
959+
960+
when(() => logger.progress(any())).thenReturn(progress);
961+
962+
final result = await commandRunner.run(
963+
[
964+
...commandArguments,
965+
skipPackagesArgument,
966+
'cli_completion',
967+
skipPackagesArgument,
968+
'very_good_test_runner',
969+
tempDirectory.path,
970+
],
971+
);
972+
973+
final errorMessage =
974+
'''No hosted dependencies found in ${tempDirectory.path} of type: direct-main.''';
975+
verify(() => logger.err(errorMessage)).called(1);
976+
977+
verify(() => progress.cancel()).called(1);
978+
979+
expect(result, equals(ExitCode.usage.code));
980+
}),
981+
);
982+
});
983+
});
984+
912985
group('exits with error', () {
913986
test(
914987
'when it did not find a pubspec.lock file at the target path',

0 commit comments

Comments
 (0)