runCommand<T> method
Future<T?>
runCommand<T>(
- List<
String> cmd, { - T? parseResult(
- RunResult result
- T? parseFail(
- dynamic error,
- StackTrace stack
- Spinner? spinner,
- bool throwOnError = true,
- LoggerService? logger,
- Duration? timeout = const Duration(seconds: 10),
- String label = 'commandRunner',
Implementation
Future<T?> runCommand<T>(
List<String> cmd, {
T? Function(RunResult result)? parseResult,
T? Function(dynamic error, StackTrace stack)? parseFail,
Spinner? spinner,
bool throwOnError = true,
LoggerService? logger,
Duration? timeout = const Duration(seconds: 10),
String label = 'commandRunner',
}) async {
spinner?.start();
try {
final result = await run(
cmd,
timeout: timeout,
);
logger?.detail('$label ExitCode: ${result.exitCode}');
logger?.detail('$label Stdout: ${result.stdout.trim()}');
logger?.detail('$label Stderr: ${result.stderr}');
if (throwOnError && result.exitCode != 0) {
throwToolExit('''
$label failed with exit code ${result.exitCode}:
${result.stdout.trim()}
${result.stderr.trim()}
''');
}
spinner?.done();
return parseResult?.call(result);
} catch (e, s) {
spinner?.failed();
logger?.detail('$label Error: $e\n$s');
return parseFail?.call(e, s);
}
}