Add option to specify download directory for assets (#989)

Co-authored-by: Oleksii Holub <1935960+Tyrrrz@users.noreply.github.com>
This commit is contained in:
Lucas LaBuff
2023-02-17 13:48:20 -05:00
committed by GitHub
parent 53ff8ba430
commit 95115f3e99
4 changed files with 67 additions and 16 deletions

View File

@@ -98,6 +98,20 @@ public abstract class ExportCommandBase : TokenCommandBase
)]
public bool ShouldReuseAssets { get; init; }
private readonly string? _assetsPath;
[CommandOption(
"media-dir",
Description = "Download assets to this directory."
)]
public string? AssetsPath
{
get => _assetsPath;
// Handle ~/ in paths on Unix systems
// https://github.com/Tyrrrz/DiscordChatExporter/pull/903
init => _assetsPath = value is not null ? Path.GetFullPath(value) : null;
}
[CommandOption(
"dateformat",
Description = "Format used when writing dates."
@@ -124,6 +138,14 @@ public abstract class ExportCommandBase : TokenCommandBase
);
}
// Assets directory should only be specified when the download assets option is set
if (!string.IsNullOrWhiteSpace(AssetsPath) && !ShouldDownloadAssets)
{
throw new CommandException(
"Option --media-dir cannot be used without --media."
);
}
// Make sure the user does not try to export all channels into a single file.
// Output path must either be a directory, or contain template tokens.
// https://github.com/Tyrrrz/DiscordChatExporter/issues/799
@@ -172,6 +194,7 @@ public abstract class ExportCommandBase : TokenCommandBase
guild,
channel,
OutputPath,
AssetsPath,
ExportFormat,
After,
Before,