2024-12-30 13:35:33 +00:00
|
|
|
import 'pending_process.dart';
|
|
|
|
|
2024-12-31 04:39:27 +00:00
|
|
|
/// A factory for creating process instances.
|
|
|
|
class Factory {
|
|
|
|
/// Create a new factory instance.
|
|
|
|
Factory();
|
2024-12-30 13:35:33 +00:00
|
|
|
|
2024-12-31 04:39:27 +00:00
|
|
|
/// Create a new pending process instance with the given command.
|
2024-12-30 13:35:33 +00:00
|
|
|
PendingProcess command(dynamic command) {
|
2024-12-31 04:39:27 +00:00
|
|
|
if (command == null) {
|
|
|
|
throw ArgumentError('Command cannot be null');
|
2024-12-30 16:14:20 +00:00
|
|
|
}
|
|
|
|
|
2024-12-31 04:39:27 +00:00
|
|
|
if (command is String && command.trim().isEmpty) {
|
|
|
|
throw ArgumentError('Command string cannot be empty');
|
2024-12-30 13:35:33 +00:00
|
|
|
}
|
|
|
|
|
2024-12-31 04:39:27 +00:00
|
|
|
if (command is List) {
|
|
|
|
if (command.isEmpty) {
|
|
|
|
throw ArgumentError('Command list cannot be empty');
|
2024-12-30 13:35:33 +00:00
|
|
|
}
|
|
|
|
|
2024-12-31 04:39:27 +00:00
|
|
|
if (command.any((element) => element is! String)) {
|
|
|
|
throw ArgumentError('Command list must contain only strings');
|
2024-12-30 13:35:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-31 04:39:27 +00:00
|
|
|
if (command is! String && command is! List) {
|
|
|
|
throw ArgumentError('Command must be a string or list of strings');
|
2024-12-30 13:35:33 +00:00
|
|
|
}
|
2024-12-31 04:39:27 +00:00
|
|
|
|
|
|
|
return PendingProcess(this)..withCommand(command);
|
2024-12-30 13:35:33 +00:00
|
|
|
}
|
|
|
|
}
|