validateAndGetInputs method
Validates common input parameters and returns validated values
Implementation
Future<Map<String, dynamic>> validateAndGetInputs() 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.', '');
}
// Validate cursor parameter
final cursorString = argResults?[cursorParameterName];
if (cursorString == null) {
throw UsageException(
'The `$cursorParameterName` parameter is required.',
'',
);
}
final cursorValue = int.tryParse(cursorString);
if (cursorValue == null) {
throw UsageException(
'The `$cursorParameterName` parameter must be a valid integer.',
'',
);
}
return {
'inputName': inputName,
'inputUuid': inputUuid,
'cursorValue': cursorValue,
};
}