import { execute, type ExecuteOptions } from './index.js';
import type { ExecuteResult } from '../types/common.js';
export function simctl(
subcommand: string,
args: string[] = [],
options?: ExecuteOptions
): ExecuteResult {
return execute('xcrun', ['simctl', subcommand, ...args], options);
}
export function simctlJson<T>(
subcommand: string,
args: string[] = [],
options?: ExecuteOptions
): T {
const result = simctl(subcommand, ['-j', ...args], options);
if (result.exitCode !== 0) {
throw new Error(`simctl ${subcommand} failed: ${result.stderr || result.stdout}`);
}
try {
return JSON.parse(result.stdout) as T;
} catch {
throw new Error(`Failed to parse simctl JSON output: ${result.stdout}`);
}
}