run method

  1. @override
Future<ExitCode> run([
  1. List<String>? args
])
override

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
Future<ExitCode> run([List<String>? args]) async {
  final argResults = args != null ? argParser.parse(args) : this.argResults!;

  final packages = {...argResults.rest};

  final recursive = argResults['recursive'] as bool;
  final dartOnly = argResults['dart-only'] as bool;
  final flutterOnly = argResults['flutter-only'] as bool;
  final includeDevDependencies = argResults['dev_dependencies'] as bool;
  final versionBump = VersionBump.values.byName(argResults['bump'] as String);
  final dryRun = argResults['dry-run'] as bool;
  final pin = argResults['pin'] as bool;

  warnDartOrFlutter(
    isDartOnly: dartOnly,
    isFlutterOnly: flutterOnly,
  );

  final pubspecs = await pubspecYaml.all(recursive: recursive);

  if (pubspecs.isEmpty) {
    logger.err('No pubspec.yaml files found.');
    return ExitCode.unavailable;
  }

  resolveFlutterAndDart(
    pubspecs,
    dartOnly: dartOnly,
    flutterOnly: flutterOnly,
    (flutterOrDart) {
      final project = path.dirname(flutterOrDart.pubspecYaml);

      final relativeDir = path.relative(
        project,
        from: fs.currentDirectory.path,
      );

      final progress =
          logger.progress('Constraining ${cyan.wrap(relativeDir)}');

      final success = constrainPubspecVersions.constrain(
        flutterOrDart.pubspecYaml,
        includeDevDependencies: includeDevDependencies,
        bump: versionBump,
        dryRun: dryRun,
        packages: packages,
        pin: pin,
      );

      progress.complete();

      logger.flush();

      return success;
    },
  );

  return ExitCode.success;
}