runDoctor function

int runDoctor(
  1. List<String> arguments, {
  2. IOSink? out,
})

flutter3d doctor's main. Returns 1 when a required check failed.

Implementation

int runDoctor(List<String> arguments, {IOSink? out}) {
  final sink = out ?? stdout;
  if (arguments.contains('-h') || arguments.contains('--help')) {
    sink.writeln(doctorUsage);
    return CliExit.ok;
  }
  // `doctor` takes nothing but `--json`: a path or a typo is refused, not
  // read as a request for the plain report.
  final unknown =
      cliOptions['doctor']!.unknownIn(arguments) ??
      arguments.where((String a) => !a.startsWith('-')).firstOrNull;
  if (unknown != null) {
    stderr.writeln(
      '${unknown.startsWith('-') ? unknownOption(unknown) : 'doctor takes no argument "$unknown".'}'
      '\n\n$doctorUsage',
    );
    return CliExit.usage;
  }
  final checks = runDoctorChecks(project: Directory.current);
  if (arguments.contains('--json')) {
    sink.writeln(
      const JsonEncoder.withIndent('  ').convert(
        cliJson('doctor', <String, Object?>{
          'checks': <Object?>[for (final c in checks) c.toJson()],
        }),
      ),
    );
  } else {
    for (final check in checks) {
      sink.writeln(
        '${check.status.mark} ${check.name.padRight(18)} ${check.detail}',
      );
      if (check.fix case final String fix
          when check.status != DoctorStatus.ok) {
        sink.writeln('     ${''.padRight(18)} $fix');
      }
    }
  }
  return checks.any((DoctorCheck c) => c.status == DoctorStatus.problem)
      ? 1
      : 0;
}