Fail if an export command is called with multiple channels but a single-file output path

Closes #799
pull/925/head
Oleksii Holub 2 years ago
parent 4e358e8e6f
commit 504c3c53cd

@ -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…
Cancel
Save