readTimeoutSecondsOption function

int? readTimeoutSecondsOption(
  1. ArgResults results, {
  2. required int defaultSeconds,
})

Reads the --timeout option as a positive whole number of seconds, falling back to defaultSeconds when the flag is absent.

Writes ERROR: Invalid value for --timeout: <raw> to stderr and returns null when the value is not a positive integer.

Implementation

int? readTimeoutSecondsOption(ArgResults results, {required int defaultSeconds}) {
  final raw = results.option('timeout');
  if (raw == null) return defaultSeconds;
  final parsed = int.tryParse(raw.trim());
  if (parsed == null || parsed <= 0) {
    stderr.writeln('ERROR: Invalid value for --timeout: $raw');
    return null;
  }
  return parsed;
}