execute method
Executes the command with the provided arguments.
Returns an integer exit code (0 for success).
Implementation
@override
Future<int> execute(List<String> arguments) async {
final ArgResults results;
try {
results = _argParser.parse(arguments);
} on FormatException catch (e) {
throw ValidationException(
'Error: ${e.message}\n\nUsage:\n flutter_setup release-notes [--path p] [--format markdown|json|text] [--output file]',
);
}
final targetPath = results['path'] as String? ?? '.';
Validators.validateExistingFlutterProject(Directory(targetPath));
final formatRaw = results['format'] as String? ?? 'markdown';
final format = ReleaseNotesFormat.parse(formatRaw);
final outputPath = results['output'] as String?;
final explicitVersion = results['version'] as String?;
final previousTag = results['previous-tag'] as String?;
final dryRun = results['dry-run'] as bool? ?? false;
String targetVersion;
if (explicitVersion != null && explicitVersion.isNotEmpty) {
targetVersion = explicitVersion;
} else {
final currentVer = _versionManager.readVersion(targetPath);
targetVersion = currentVer.versionName;
}
final notes = await _generator.generate(
projectPath: targetPath,
version: targetVersion,
previousTag: previousTag,
);
final rendered = _generator.render(notes, format);
if (outputPath != null && outputPath.isNotEmpty) {
final file = File(outputPath);
if (dryRun) {
_output.info('[DRY-RUN] Would write release notes to "$outputPath":\n');
_output.info(rendered);
} else {
await file.writeAsString(rendered);
_output.info('Successfully wrote release notes to "$outputPath".');
}
} else {
_output.info(rendered);
}
return 0;
}