run method
Starts the log removal process, which includes selecting the operation type, specifying the target path, and choosing the log patterns to remove.
The method runs asynchronously and displays a progress bar while cleaning the logs.
Implementation
Future<void> run() async {
console.setForegroundColor(
ConsoleColor.brightBlue); // Set console color for the message
final operationType =
directorySelector.selectOperation(); // Select operation type
targetPath =
directorySelector.selectTargetPath(operationType); // Select target path
final patterns =
selectLogPatterns(); // Get the log patterns selected by the user
final logCleaner =
LogCleaner(targetPath, patterns); // Create the LogCleaner instance
console.setForegroundColor(
ConsoleColor.cyan); // Set console color for the next message
print('\nStarting log removal process...'); // Notify user of process start
// Perform log cleaning and wait for result
final result = await logCleaner.cleanLogs();
console.setForegroundColor(
ConsoleColor.cyan); // Set console color for result message
print('\nā
${result.message}'); // Display the result message
print(
'š Files Processed: ${result.filesProcessed}'); // Show the number of files processed
// Display the cleaned files or a message that no logs were found
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}'); // Print the cleaned files
}
}
}