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 {
// Validate that at least one of input-name or input-uuid is provided
final inputName = argResults?['input-name'];
final inputUuid = argResults?['input-uuid'];
if (inputName == null && inputUuid == null) {
throw UsageException(
'Your request must contain at least one of the following fields: `input-name` or `input-uuid`.',
'',
);
}
// Validate that input-name is a string if provided
if (inputName != null && inputName is! String) {
throw UsageException('The `input-name` parameter must be a string.', '');
}
// Validate that input-uuid is a string if provided
if (inputUuid != null && inputUuid is! String) {
throw UsageException('The `input-uuid` parameter must be a string.', '');
}
// Get and validate media action
final mediaActionString = argResults?['media-action'] as String;
// Convert string to enum
final mediaAction = ObsMediaInputAction.values.firstWhere(
(action) => action.name == mediaActionString,
orElse: () =>
throw UsageException('Invalid media action: $mediaActionString', ''),
);
await initializeObs();
await obs.mediaInputs.triggerMediaInputAction(
inputName: inputName,
inputUuid: inputUuid,
mediaAction: mediaAction,
);
obs.close();
}