From cc03228f72e6e7bf7e9934c4723cd2d99ff9eaa0 Mon Sep 17 00:00:00 2001 From: Jonas Sander <29028262+Jonas-Sander@users.noreply.github.com> Date: Wed, 7 Feb 2024 22:08:40 +0100 Subject: [PATCH] Add `--only` option to sharezone cli. The option allows to run a `ConcurrentCommand` only for the specified package names. E.g.: `sz analyze --only sz_repo_cli`, `sz test sharezone,abgabe_client_lib`. --- .../src/common/src/concurrent_command.dart | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/tools/sz_repo_cli/lib/src/common/src/concurrent_command.dart b/tools/sz_repo_cli/lib/src/common/src/concurrent_command.dart index 6236b604d..a0151f3eb 100644 --- a/tools/sz_repo_cli/lib/src/common/src/concurrent_command.dart +++ b/tools/sz_repo_cli/lib/src/common/src/concurrent_command.dart @@ -15,6 +15,11 @@ import 'package:sz_repo_cli/src/common/common.dart'; abstract class ConcurrentCommand extends CommandBase { ConcurrentCommand(super.context) { argParser + ..addOption( + 'only', + help: + 'Only run the task for the given package(s). Package names can be separated by comma. E.g. `--only package1` or `--only=package1,package2`.', + ) ..addConcurrencyOption(defaultMaxConcurrency: defaultMaxConcurrency) ..addPackageTimeoutOption( defaultInMinutes: defaultPackageTimeout.inMinutes); @@ -54,7 +59,25 @@ abstract class ConcurrentCommand extends CommandBase { /// /// Can be overridden to e.g. add a filter (`.where((package) => /// package.hasTestDirectory`). - Stream get packagesToProcess => repo.streamPackages(); + Stream get packagesToProcess { + var stream = repo.streamPackages(); + + final onlyPackageNames = _parseOnlyArg(); + if (onlyPackageNames.isNotEmpty) { + stream = + stream.where((package) => onlyPackageNames.contains(package.name)); + } + + return stream; + } + + List _parseOnlyArg() { + final onlyArg = argResults!['only'] as String?; + if (onlyArg == null) { + return []; + } + return onlyArg.split(','); + } @override Future run() async {