run method

Future<void> run()

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
    }
  }
}