run method
Runs the log removal process.
This method sets the console text color, selects the operation type and target path, selects log patterns, and initializes the log cleaner. It then starts the log removal process and prints the result, including the number of files processed and the list of cleaned files, if any.
The console text color is changed to indicate different stages of the process.
Throws an exception if the log removal process fails.
Implementation
Future<void> run() async {
console.setForegroundColor(ConsoleColor.brightBlue);
final operationType = directorySelector.selectOperation();
targetPath = directorySelector.selectTargetPath(operationType);
final patterns = selectLogPatterns();
final logCleaner = LogCleaner(targetPath, patterns);
console.setForegroundColor(ConsoleColor.cyan);
print('\nStarting log removal process...');
final result = await logCleaner.cleanLogs();
if (result.success) {
console.setForegroundColor(ConsoleColor.cyan);
print('\nā
${result.message}');
print('š Files Processed: ${result.filesProcessed}');
if (result.cleanedFiles.isEmpty) {
console.setForegroundColor(ConsoleColor.brightBlue);
print('š All clean! No unwanted logs found.');
} else {
console.setForegroundColor(ConsoleColor.magenta);
print('š Cleaned Files:');
for (var file in result.cleanedFiles) {
print('- ${file.path}');
}
}
} else {
console.setForegroundColor(ConsoleColor.brightRed);
print('ā ${result.message}');
throw Exception('Log removal process failed: ${result.message}');
}
console.resetColorAttributes();
}