mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-06-01 07:18:23 -04:00
Fail if an export command is called with multiple channels but a single-file output path
Closes #799
This commit is contained in:
parent
4e358e8e6f
commit
504c3c53cd
2 changed files with 19 additions and 3 deletions
|
@ -14,13 +14,14 @@ using DiscordChatExporter.Core.Exceptions;
|
|||
using DiscordChatExporter.Core.Exporting;
|
||||
using DiscordChatExporter.Core.Exporting.Filtering;
|
||||
using DiscordChatExporter.Core.Exporting.Partitioning;
|
||||
using DiscordChatExporter.Core.Utils;
|
||||
using Gress;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Commands.Base;
|
||||
|
||||
public abstract class ExportCommandBase : TokenCommandBase
|
||||
{
|
||||
private string _outputPath = Directory.GetCurrentDirectory();
|
||||
private readonly string _outputPath = Directory.GetCurrentDirectory();
|
||||
|
||||
[CommandOption(
|
||||
"output",
|
||||
|
@ -98,9 +99,20 @@ public abstract class ExportCommandBase : TokenCommandBase
|
|||
{
|
||||
var cancellationToken = console.RegisterCancellationHandler();
|
||||
|
||||
// https://github.com/Tyrrrz/DiscordChatExporter/issues/425
|
||||
if (ShouldReuseMedia && !ShouldDownloadMedia)
|
||||
{
|
||||
throw new CommandException("Option --reuse-media cannot be used without --media.");
|
||||
throw new CommandException(
|
||||
"Option --reuse-media cannot be used without --media."
|
||||
);
|
||||
}
|
||||
|
||||
// https://github.com/Tyrrrz/DiscordChatExporter/issues/799
|
||||
if (channels.Count > 1 && !PathEx.IsDirectoryPath(OutputPath) && !OutputPath.Contains('%'))
|
||||
{
|
||||
throw new CommandException(
|
||||
"Attempted to export multiple channels, but the output path is neither a directory nor a template."
|
||||
);
|
||||
}
|
||||
|
||||
var errors = new ConcurrentDictionary<Channel, string>();
|
||||
|
@ -219,4 +231,4 @@ public abstract class ExportCommandBase : TokenCommandBase
|
|||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,4 +17,8 @@ public static class PathEx
|
|||
|
||||
return buffer.ToString();
|
||||
}
|
||||
|
||||
public static bool IsDirectoryPath(string path) =>
|
||||
path.EndsWith(Path.DirectorySeparatorChar) ||
|
||||
path.EndsWith(Path.AltDirectorySeparatorChar);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue