run method
Runs this command.
The return value is wrapped in a Future
if necessary and returned by
CommandRunner.runCommand
.
Implementation
@override
void run() async {
await initializeObs();
final eventSubscriptions = argResults!['event-subscriptions']
.toString()
.split(',');
final eventSubscriptionMap = EventSubscription.values.asNameMap();
var finalSubscriptions = 0;
for (var eventSubscription in eventSubscriptions) {
if (eventSubscriptionMap.containsKey(eventSubscription)) {
finalSubscriptions += eventSubscriptionMap[eventSubscription]!.code;
}
}
await obs.listenForMask(finalSubscriptions);
final commandList = CommandLineConverter().convert(argResults?['command']);
if (argResults?['command'] != null) {
obs.addFallbackListener((event) async {
final echo = await Process.start('printf', ['$event']);
final cmd = await Process.start(commandList[0], commandList.sublist(1));
echo.stdout.pipe(cmd.stdin);
cmd.stdout
.transform(utf8.decoder)
.forEach((value) => print(value.trim()));
});
} else {
obs.addFallbackListener((event) => print(event));
}
}