Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sz exec command. #1130

Merged
merged 10 commits into from
Oct 22, 2023
1 change: 1 addition & 0 deletions tools/sz_repo_cli/lib/src/commands/commands.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export 'src/analyze_command.dart' show AnalyzeCommand;
export 'src/deploy_command.dart';
export 'src/deploy_web_app_command.dart';
export 'src/do_stuff_command.dart';
export 'src/exec_command.dart';
export 'src/fix_comment_spacing_command.dart' show FixCommentSpacingCommand;
export 'src/pub_command.dart';
export 'src/pub_get_command.dart' show PubGetCommand;
Expand Down
68 changes: 68 additions & 0 deletions tools/sz_repo_cli/lib/src/commands/src/exec_command.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) 2022 Sharezone UG (haftungsbeschränkt)
// Licensed under the EUPL-1.2-or-later.
//
// You may obtain a copy of the Licence at:
// https://joinup.ec.europa.eu/software/page/eupl
//
// SPDX-License-Identifier: EUPL-1.2

import 'dart:async';

import 'package:sz_repo_cli/src/common/common.dart';

class ExecCommand extends ConcurrentCommand {
ExecCommand(super.processRunner, super.repo) {
argParser
..addFlag('onlyFlutter',
help: 'Only run the command for Flutter packages.', defaultsTo: false)
..addFlag('onlyDart',
help: 'Only run the command for Dart packages.', defaultsTo: false);
}

@override
final String name = 'exec';

@override
final String description = 'Runs a given command for all/multiple packages.';

@override
Duration get defaultPackageTimeout => const Duration(minutes: 5);

bool get onlyFlutter => argResults!['onlyFlutter'] as bool;
bool get onlyDart => argResults!['onlyDart'] as bool;

@override
Stream<Package> get packagesToProcess {
List<bool Function(Package)> testFuncs = [];
if (onlyDart) testFuncs.add((package) => package.isPureDartPackage);
if (onlyFlutter) testFuncs.add((package) => package.isFlutterPackage);

return super.packagesToProcess.where((event) {
for (var testFunc in testFuncs) {
if (testFunc(event)) {
continue;
} else {
return false;
}
}
return true;
});
}

@override
Future<void> runSetup() async {
if (argResults!.rest.isEmpty) {
throw ArgumentError(
'No command given. Please provide a command like this:\n'
'sz_repo_cli exec --onlyFlutter -- fvm dart fix --apply');
}
}

@override
Future<void> runTaskForPackage(Package package) async {
await processRunner.run(
argResults!.rest,
workingDirectory: package.location,
);
}
}
1 change: 1 addition & 0 deletions tools/sz_repo_cli/lib/src/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Future<void> main(List<String> args) async {
..addCommand(AnalyzeCommand(processRunner, repo))
..addCommand(TestCommand(processRunner, repo))
..addCommand(FormatCommand(processRunner, repo))
..addCommand(ExecCommand(processRunner, repo))
..addCommand(DoStuffCommand(repo))
..addCommand(FixCommentSpacingCommand(repo))
..addCommand(
Expand Down
Loading