runSimctl function

Future<String?> runSimctl(
  1. List<String> args
)

Runs xcrun simctl with the given args and returns the result.

Returns null on success (exit code 0), or an error message string on failure. The caller is responsible for mapping the error into a sealed result variant.

Implementation

Future<String?> runSimctl(List<String> args) async {
  try {
    final result = await Process.run('xcrun', ['simctl', ...args]);
    if (result.exitCode != 0) {
      final err = (result.stderr as String).trim();
      return err.isNotEmpty ? err : 'simctl exited with code ${result.exitCode}';
    }
    return null;
  } catch (e) {
    return 'Failed to run xcrun simctl: $e';
  }
}