mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-05-11 10:26:57 +02:00
Split error and warning printing into separate code paths
This commit is contained in:
parent
3c0bf8a125
commit
fb86fee58c
1 changed files with 39 additions and 24 deletions
|
@ -256,33 +256,48 @@ public abstract class ExportCommandBase : DiscordCommandBase
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print errors and warnings
|
// Print warnings
|
||||||
if (errorsByChannel.Any() || warningsByChannel.Any())
|
if (warningsByChannel.Any())
|
||||||
{
|
{
|
||||||
var tuples = new List<(ConcurrentDictionary<Channel, string>, ConsoleColor, string)>
|
await console.Output.WriteLineAsync();
|
||||||
|
|
||||||
|
using (console.WithForegroundColor(ConsoleColor.Yellow))
|
||||||
{
|
{
|
||||||
(errorsByChannel, ConsoleColor.Red, "Failed to export the following channels:"),
|
await console.Error.WriteLineAsync(
|
||||||
(warningsByChannel, ConsoleColor.Yellow, "No messages exported for the following channels:")
|
$"Warnings reported for the following channel(s):"
|
||||||
};
|
);
|
||||||
|
|
||||||
foreach (var (messages, color, title) in tuples) {
|
|
||||||
if (! messages.Any())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
await console.Output.WriteLineAsync();
|
|
||||||
|
|
||||||
using (console.WithForegroundColor(color))
|
|
||||||
await console.Error.WriteLineAsync(title);
|
|
||||||
|
|
||||||
foreach (var (channel, message) in messages)
|
|
||||||
{
|
|
||||||
await console.Error.WriteAsync($"{channel.GetHierarchicalName()}: ");
|
|
||||||
using (console.WithForegroundColor(color))
|
|
||||||
await console.Error.WriteLineAsync(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
await console.Error.WriteLineAsync();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (var (channel, message) in warningsByChannel)
|
||||||
|
{
|
||||||
|
await console.Error.WriteAsync($"{channel.GetHierarchicalName()}: ");
|
||||||
|
using (console.WithForegroundColor(ConsoleColor.Yellow))
|
||||||
|
await console.Error.WriteLineAsync(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
await console.Error.WriteLineAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print errors
|
||||||
|
if (errorsByChannel.Any())
|
||||||
|
{
|
||||||
|
await console.Output.WriteLineAsync();
|
||||||
|
|
||||||
|
using (console.WithForegroundColor(ConsoleColor.Red))
|
||||||
|
{
|
||||||
|
await console.Error.WriteLineAsync(
|
||||||
|
$"Failed to export the following channel(s):"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var (channel, message) in errorsByChannel)
|
||||||
|
{
|
||||||
|
await console.Error.WriteAsync($"{channel.GetHierarchicalName()}: ");
|
||||||
|
using (console.WithForegroundColor(ConsoleColor.Red))
|
||||||
|
await console.Error.WriteLineAsync(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
await console.Error.WriteLineAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fail the command only if ALL channels failed to export.
|
// Fail the command only if ALL channels failed to export.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue