diff --git a/FindDuplicates/ListCommand.cs b/FindDuplicates/ListCommand.cs index b18ca92..206c672 100644 --- a/FindDuplicates/ListCommand.cs +++ b/FindDuplicates/ListCommand.cs @@ -1,6 +1,4 @@ using System.Collections.Concurrent; -using System.Diagnostics; -using System.Security; using System.Security.Cryptography; using System.Text; using Spectre.Console; @@ -110,7 +108,7 @@ internal sealed class ListCommand : AsyncCommand { string relativeFilePath = Path.GetRelativePath(inputDirectory.FullName, file.FullName); AnsiConsole.MarkupLineInterpolated($"Checking hash for [cyan]{relativeFilePath}[/]"); - tasks.Add(Task.Run(() => ProcessFile(file))); + tasks.Add(Task.Run(() => ProcessFile(file, settings))); } } catch (Exception ex) @@ -120,7 +118,7 @@ internal sealed class ListCommand : AsyncCommand } } - private void ProcessFile(FileInfo file) + private void ProcessFile(FileInfo file, ListSettings settings) { Span buffer = stackalloc byte[64]; try @@ -129,7 +127,8 @@ internal sealed class ListCommand : AsyncCommand using BufferedStream bufferedStream = new BufferedStream(stream, 1048576 /* 1MB */); SHA512.HashData(bufferedStream, buffer); string hash = ByteSpanToString(buffer); - Trace.WriteLine($"{file.FullName}: {hash}"); + if (settings.Verbose) + AnsiConsole.WriteLine($"{file.FullName} ->\n {hash}"); if (!_fileHashMap.TryGetValue(hash, out List? cache)) _fileHashMap[hash] = cache = new List(); diff --git a/FindDuplicates/ListSettings.cs b/FindDuplicates/ListSettings.cs index 44a4738..f4c6a13 100644 --- a/FindDuplicates/ListSettings.cs +++ b/FindDuplicates/ListSettings.cs @@ -13,4 +13,9 @@ internal sealed class ListSettings : CommandSettings [Description("When this flag is set, the directory will be scanned recursively. This may take longer.")] [DefaultValue(false)] public bool Recursive { get; set; } = false; + + [CommandOption("--verbose")] + [Description("Enable verbose output.")] + [DefaultValue(false)] + public bool Verbose { get; set; } = false; }