1
0
mirror of https://github.com/oliverbooth/fdup.git synced 2024-11-09 23:25:42 +00:00

refactor: move stack push to method

reduces method complexity and now Rider isn't crying
This commit is contained in:
Oliver Booth 2024-04-17 14:24:54 +01:00
parent 435318cd20
commit 3396c2bc74
Signed by: oliverbooth
GPG Key ID: E60B570D1B7557B5

View File

@ -89,18 +89,7 @@ internal sealed class ListCommand : AsyncCommand<ListSettings>
if (relativePath != ".") if (relativePath != ".")
AnsiConsole.MarkupLineInterpolated($"Searching [cyan]{relativePath}[/]"); AnsiConsole.MarkupLineInterpolated($"Searching [cyan]{relativePath}[/]");
if (settings.Recursive) AddChildDirectories(settings, currentDirectory, directoryStack);
{
try
{
foreach (DirectoryInfo childDirectory in currentDirectory.EnumerateDirectories())
directoryStack.Push(childDirectory);
}
catch (Exception ex)
{
AnsiConsole.MarkupLineInterpolated($"[red]Error:[/] {ex.Message}");
}
}
try try
{ {
@ -142,6 +131,22 @@ internal sealed class ListCommand : AsyncCommand<ListSettings>
} }
} }
private static void AddChildDirectories(ListSettings settings, DirectoryInfo directory, Stack<DirectoryInfo> stack)
{
if (!settings.Recursive)
return;
try
{
foreach (DirectoryInfo childDirectory in directory.EnumerateDirectories())
stack.Push(childDirectory);
}
catch (Exception ex)
{
AnsiConsole.MarkupLineInterpolated($"[red]Error:[/] {ex.Message}");
}
}
private static string ByteSpanToString(ReadOnlySpan<byte> buffer) private static string ByteSpanToString(ReadOnlySpan<byte> buffer)
{ {
var builder = new StringBuilder(); var builder = new StringBuilder();