From 316e8c6ea8abebf02fbbc3e9466b4e2d5d75f9aa Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 3 Apr 2026 16:12:47 +0000 Subject: [PATCH] Simplify stdin reading: use ReadAllLinesAsync extension and Snowflake.Parse Agent-Logs-Url: https://github.com/Tyrrrz/DiscordChatExporter/sessions/59c1113d-3c9c-4900-a9b0-5c6116ce7c75 Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> --- .../Commands/ExportChannelsCommand.cs | 23 +++---------------- .../Utils/Extensions/ConsoleExtensions.cs | 13 +++++++++++ 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/DiscordChatExporter.Cli/Commands/ExportChannelsCommand.cs b/DiscordChatExporter.Cli/Commands/ExportChannelsCommand.cs index fc5f4628..22e74c25 100644 --- a/DiscordChatExporter.Cli/Commands/ExportChannelsCommand.cs +++ b/DiscordChatExporter.Cli/Commands/ExportChannelsCommand.cs @@ -4,6 +4,7 @@ using CliFx; using CliFx.Binding; using CliFx.Infrastructure; using DiscordChatExporter.Cli.Commands.Base; +using DiscordChatExporter.Cli.Utils.Extensions; using DiscordChatExporter.Core.Discord; using DiscordChatExporter.Core.Discord.Data; using DiscordChatExporter.Core.Utils.Extensions; @@ -33,26 +34,8 @@ public partial class ExportChannelsCommand : ExportCommandBase var channelIds = new List(ChannelIds); if (channelIds.Count == 0 && console.IsInputRedirected) { - var lineNumber = 0; - string? line; - while ((line = await console.Input.ReadLineAsync()) is not null) - { - lineNumber++; - line = line.Trim(); - if (string.IsNullOrEmpty(line)) - continue; - - var snowflake = Snowflake.TryParse(line); - if (snowflake is null) - { - throw new CommandException( - $"Invalid channel ID on line {lineNumber}: '{line}'. " - + "Each line must contain a valid channel ID." - ); - } - - channelIds.Add(snowflake.Value); - } + await foreach (var line in console.Input.ReadAllLinesAsync()) + channelIds.Add(Snowflake.Parse(line)); } if (channelIds.Count == 0) diff --git a/DiscordChatExporter.Cli/Utils/Extensions/ConsoleExtensions.cs b/DiscordChatExporter.Cli/Utils/Extensions/ConsoleExtensions.cs index d7d47c8c..80e40253 100644 --- a/DiscordChatExporter.Cli/Utils/Extensions/ConsoleExtensions.cs +++ b/DiscordChatExporter.Cli/Utils/Extensions/ConsoleExtensions.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.IO; using System.Threading.Tasks; using CliFx.Infrastructure; using Spectre.Console; @@ -61,4 +63,15 @@ internal static class ConsoleExtensions progressTask.StopTask(); } } + + public static async IAsyncEnumerable ReadAllLinesAsync(this TextReader reader) + { + string? line; + while ((line = await reader.ReadLineAsync()) is not null) + { + line = line.Trim(); + if (!string.IsNullOrEmpty(line)) + yield return line; + } + } }