tryParse static method
Parses a spec string of the form <format> or <format>:<file>.
The string is split at the first colon, so file paths may themselves
contain colons (e.g. json:C:/out.json → file C:/out.json). Returns
null for null, an empty string, or an unrecognized format. A trailing
empty file part (csv:) yields a spec with no filePath.
Implementation
static OutputSpec? tryParse(String? value) {
if (value == null || value.isEmpty) return null;
final colonIdx = value.indexOf(':');
if (colonIdx == -1) {
final format = OutputFormat.tryParse(value);
if (format == null) return null;
return OutputSpec(format: format);
}
final formatStr = value.substring(0, colonIdx);
final filePath = value.substring(colonIdx + 1);
final format = OutputFormat.tryParse(formatStr);
if (format == null) return null;
return OutputSpec(
format: format,
filePath: filePath.isEmpty ? null : filePath,
);
}