From 53cebd82eb3bf79c8d2b6e673b6cb61fc29874e3 Mon Sep 17 00:00:00 2001 From: Andrew Kolos Date: Sun, 22 Nov 2020 13:45:19 -0500 Subject: [PATCH] [CLI] Print error and exit if reuse-media option is used without media option (#433) --- .../Commands/Base/ExportCommandBase.cs | 9 +++++++++ DiscordChatExporter.Cli/Commands/ExportChannelCommand.cs | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/DiscordChatExporter.Cli/Commands/Base/ExportCommandBase.cs b/DiscordChatExporter.Cli/Commands/Base/ExportCommandBase.cs index ebc1b56e..cecd6842 100644 --- a/DiscordChatExporter.Cli/Commands/Base/ExportCommandBase.cs +++ b/DiscordChatExporter.Cli/Commands/Base/ExportCommandBase.cs @@ -3,6 +3,7 @@ using System.IO; using System.Threading.Tasks; using CliFx; using CliFx.Attributes; +using CliFx.Exceptions; using CliFx.Utilities; using DiscordChatExporter.Domain.Discord.Models; using DiscordChatExporter.Domain.Exporting; @@ -11,6 +12,7 @@ namespace DiscordChatExporter.Cli.Commands.Base { public abstract class ExportCommandBase : TokenCommandBase { + [CommandOption("output", 'o', Description = "Output file or directory path.")] public string OutputPath { get; set; } = Directory.GetCurrentDirectory(); @@ -69,6 +71,13 @@ namespace DiscordChatExporter.Cli.Commands.Base console.Output.WriteLine("Done."); } + public void ExecuteAsync() + { + if (ShouldReuseMedia && !ShouldDownloadMedia) + { + throw new CommandException("The --reuse-media option cannot be used without the --media option."); + } + } protected async ValueTask ExportAsync(IConsole console, Channel channel) { var guild = await GetDiscordClient().GetGuildAsync(channel.GuildId); diff --git a/DiscordChatExporter.Cli/Commands/ExportChannelCommand.cs b/DiscordChatExporter.Cli/Commands/ExportChannelCommand.cs index 446d12a3..d3d7b246 100644 --- a/DiscordChatExporter.Cli/Commands/ExportChannelCommand.cs +++ b/DiscordChatExporter.Cli/Commands/ExportChannelCommand.cs @@ -12,7 +12,10 @@ namespace DiscordChatExporter.Cli.Commands Description = "Channel ID.")] public string ChannelId { get; set; } = ""; - public override async ValueTask ExecuteAsync(IConsole console) => + public override async ValueTask ExecuteAsync(IConsole console) + { + base.ExecuteAsync(); await ExportAsync(console, ChannelId); + } } } \ No newline at end of file