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 dir = workingDirectory ?? Directory.current.path;
  final configPath = p.join(dir, 'rekeens.yaml');
  final force = argResults!['force'] as bool;
  final dryRun = argResults!['dry-run'] as bool;

  if (File(configPath).existsSync() && !force) {
    throw UsageException(
      'rekeens.yaml already exists at $configPath. Use --force to overwrite.',
      usage,
    );
  }

  if (dryRun) {
    logger.warn('DRY RUN: would write rekeens.yaml -> $configPath');
    return;
  }

  File(configPath).writeAsStringSync(defaultConfigContent);
  logger.success('Created rekeens.yaml at $configPath');
}