run method

  1. @override
Future<void> run()
override

Runs this command.

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

Implementation

@override
Future<void> run() async {
  final noCommit = argResults!['no-commit'] as bool;
  final noTag = argResults!['no-tag'] as bool;
  final dryRun = argResults!['dry-run'] as bool;
  final push = argResults!['push'] as bool;

  if (argResults!.rest.isEmpty) {
    throw UsageException('You must specify the version to set', usage);
  }

  final version = argResults!.rest.first;

  if (!isValidVersionWithBuild(version)) {
    throw UsageException(
      'Invalid version: "$version". Must include build metadata (e.g., 1.2.3+4)',
      usage,
    );
  }

  final executor = dryRun ? DryRunReleaseExecutor() : RealReleaseExecutor();
  final service = VersionService(executor);

  await service.setVersion(
    version,
    noCommit: noCommit,
    noTag: noTag,
    push: push,
  );

  print('Version set to $version');
}