runDoctor function
int
runDoctor(
- List<
String> args, { - StringSink? out,
- StringSink? err,
- Map<
String, String> ? environment, - NativeManifest? manifest,
- String? machineBundle,
- String command = 'local_inference:doctor',
Runs the doctor for the command line args and returns the exit status (see doctorUsage). The report goes to
out (stdout by default), usage errors to err (stderr). environment, manifest and machineBundle replace
the process environment, the embedded manifest and this computer's bundle (for tests).
Implementation
int runDoctor(
List<String> args, {
StringSink? out,
StringSink? err,
Map<String, String>? environment,
NativeManifest? manifest,
String? machineBundle,
String command = 'local_inference:doctor',
}) {
final output = out ?? stdout;
final errors = err ?? stderr;
var json = false, strict = false, verify = false, install = false;
final folders = <String>[];
for (final arg in args) {
switch (arg) {
case '--json':
json = true;
case '--strict':
strict = true;
case '--verify-natives':
verify = true;
case '--install-ios-script':
install = true;
case '-h' || '--help':
output.writeln(doctorUsage(command));
return 0;
default:
if (arg.startsWith('-')) {
errors.writeln('doctor: unknown option $arg\n\n${doctorUsage(command)}');
return 2;
}
folders.add(arg);
}
}
if (folders.length > 1) {
errors.writeln('doctor: one host folder at most, got ${folders.join(' ')}\n\n${doctorUsage(command)}');
return 2;
}
final dir = p.normalize(p.absolute(folders.isEmpty ? Directory.current.path : folders.single));
if (!File(p.join(dir, 'pubspec.yaml')).existsSync()) {
errors.writeln(
'doctor: no pubspec.yaml in $dir: run the doctor in the host app or package, or name its folder '
'(dart run $command --help)',
);
return 2;
}
final HostProject host;
try {
host = HostProject.load(dir);
} on FormatException catch (e) {
errors.writeln('doctor: ${e.message}');
return 2;
} on FileSystemException catch (e) {
errors.writeln('doctor: cannot read ${e.path ?? p.join(dir, 'pubspec.yaml')}: ${e.message}');
return 2;
}
if (install) return installIosScript(host, out: output, err: errors, command: command);
final report = Doctor(
dir,
strict: strict,
verifyNatives: verify,
environment: environment,
manifest: manifest,
machineBundle: machineBundle,
).run();
output.write(json ? '${report.toJsonText()}\n' : report.render());
return report.exitCode;
}