Refine ReadLinesAsync: pattern matching, rename, cancellation token

Agent-Logs-Url: https://github.com/Tyrrrz/DiscordChatExporter/sessions/e4a61491-645a-418c-91cd-74e835baaf44

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-04-03 22:26:56 +00:00 committed by GitHub
parent 316e8c6ea8
commit f656234c38
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 4 deletions

View file

@ -34,7 +34,7 @@ public partial class ExportChannelsCommand : ExportCommandBase
var channelIds = new List<Snowflake>(ChannelIds);
if (channelIds.Count == 0 && console.IsInputRedirected)
{
await foreach (var line in console.Input.ReadAllLinesAsync())
await foreach (var line in console.Input.ReadLinesAsync(cancellationToken))
channelIds.Add(Snowflake.Parse(line));
}

View file

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using CliFx.Infrastructure;
using Spectre.Console;
@ -64,10 +65,13 @@ internal static class ConsoleExtensions
}
}
public static async IAsyncEnumerable<string> ReadAllLinesAsync(this TextReader reader)
public static async IAsyncEnumerable<string> ReadLinesAsync(
this TextReader reader,
[System.Runtime.CompilerServices.EnumeratorCancellation]
CancellationToken cancellationToken = default
)
{
string? line;
while ((line = await reader.ReadLineAsync()) is not null)
while (await reader.ReadLineAsync(cancellationToken) is { } line)
{
line = line.Trim();
if (!string.IsNullOrEmpty(line))