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 changelog [--path p] [--init] [--overwrite] [--dry-run]',
);
}
final targetPath = results['path'] as String? ?? '.';
Validators.validateExistingFlutterProject(Directory(targetPath));
final init = results['init'] as bool? ?? false;
final overwrite = results['overwrite'] as bool? ?? false;
final dryRun = results['dry-run'] as bool? ?? false;
final explicitVersion = results['version'] as String?;
final previousTag = results['previous-tag'] as String?;
String targetVersion;
if (explicitVersion != null && explicitVersion.isNotEmpty) {
targetVersion = explicitVersion;
} else {
final currentVer = _versionManager.readVersion(targetPath);
targetVersion = currentVer.versionName;
}
final notes = await _notesGenerator.generate(
projectPath: targetPath,
version: targetVersion,
previousTag: previousTag,
);
final result = await _manager.updateChangelog(
targetPath,
notes,
init: init,
overwrite: overwrite,
dryRun: dryRun,
);
if (dryRun) {
_output.info('${result.message}\n');
_output.info(result.content);
} else {
_output.info(result.message);
}
return 0;
}