mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-05-29 05:55:21 -04:00
Refactor output path usage in CLI
This commit is contained in:
parent
991dfccf3c
commit
20ff4a15eb
4 changed files with 20 additions and 27 deletions
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DiscordChatExporter.Cli.Verbs.Options;
|
using DiscordChatExporter.Cli.Verbs.Options;
|
||||||
using DiscordChatExporter.Core.Helpers;
|
using DiscordChatExporter.Core.Helpers;
|
||||||
|
@ -32,15 +33,15 @@ namespace DiscordChatExporter.Cli.Verbs
|
||||||
Options.After, Options.Before);
|
Options.After, Options.Before);
|
||||||
|
|
||||||
// Generate file path if not set or is a directory
|
// Generate file path if not set or is a directory
|
||||||
var filePath = Options.FilePath;
|
var filePath = Options.OutputPath;
|
||||||
if (filePath == null || filePath.EndsWith("/") || filePath.EndsWith("\\"))
|
if (filePath.IsBlank() || ExportHelper.IsDirectoryPath(filePath))
|
||||||
{
|
{
|
||||||
// Generate default file name
|
// Generate default file name
|
||||||
var defaultFileName = ExportHelper.GetDefaultExportFileName(Options.ExportFormat, chatLog.Guild,
|
var fileName = ExportHelper.GetDefaultExportFileName(Options.ExportFormat, chatLog.Guild,
|
||||||
chatLog.Channel, Options.After, Options.Before);
|
chatLog.Channel, Options.After, Options.Before);
|
||||||
|
|
||||||
// Append the file name to the file path
|
// Combine paths
|
||||||
filePath += defaultFileName;
|
filePath = Path.Combine(filePath ?? "", fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Export
|
// Export
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
@ -48,17 +49,12 @@ namespace DiscordChatExporter.Cli.Verbs
|
||||||
var chatLog = await dataService.GetChatLogAsync(Options.GetToken(), channel,
|
var chatLog = await dataService.GetChatLogAsync(Options.GetToken(), channel,
|
||||||
Options.After, Options.Before);
|
Options.After, Options.Before);
|
||||||
|
|
||||||
// Generate file path if not set or is a directory
|
// Generate default file name
|
||||||
var filePath = Options.FilePath;
|
var fileName = ExportHelper.GetDefaultExportFileName(Options.ExportFormat, chatLog.Guild,
|
||||||
if (filePath == null || filePath.EndsWith("/") || filePath.EndsWith("\\"))
|
chatLog.Channel, Options.After, Options.Before);
|
||||||
{
|
|
||||||
// Generate default file name
|
|
||||||
var defaultFileName = ExportHelper.GetDefaultExportFileName(Options.ExportFormat, chatLog.Guild,
|
|
||||||
chatLog.Channel, Options.After, Options.Before);
|
|
||||||
|
|
||||||
// Append the file name to the file path
|
// Generate file path
|
||||||
filePath += defaultFileName;
|
var filePath = Path.Combine(Options.OutputPath ?? "", fileName);
|
||||||
}
|
|
||||||
|
|
||||||
// Export
|
// Export
|
||||||
exportService.ExportChatLog(chatLog, filePath, Options.ExportFormat, Options.PartitionLimit);
|
exportService.ExportChatLog(chatLog, filePath, Options.ExportFormat, Options.PartitionLimit);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
@ -49,17 +50,12 @@ namespace DiscordChatExporter.Cli.Verbs
|
||||||
var chatLog = await dataService.GetChatLogAsync(Options.GetToken(), channel,
|
var chatLog = await dataService.GetChatLogAsync(Options.GetToken(), channel,
|
||||||
Options.After, Options.Before);
|
Options.After, Options.Before);
|
||||||
|
|
||||||
// Generate file path if not set or is a directory
|
// Generate default file name
|
||||||
var filePath = Options.FilePath;
|
var fileName = ExportHelper.GetDefaultExportFileName(Options.ExportFormat, chatLog.Guild,
|
||||||
if (filePath == null || filePath.EndsWith("/") || filePath.EndsWith("\\"))
|
chatLog.Channel, Options.After, Options.Before);
|
||||||
{
|
|
||||||
// Generate default file name
|
|
||||||
var defaultFileName = ExportHelper.GetDefaultExportFileName(Options.ExportFormat, chatLog.Guild,
|
|
||||||
chatLog.Channel, Options.After, Options.Before);
|
|
||||||
|
|
||||||
// Append the file name to the file path
|
// Generate file path
|
||||||
filePath += defaultFileName;
|
var filePath = Path.Combine(Options.OutputPath ?? "", fileName);
|
||||||
}
|
|
||||||
|
|
||||||
// Export
|
// Export
|
||||||
exportService.ExportChatLog(chatLog, filePath, Options.ExportFormat, Options.PartitionLimit);
|
exportService.ExportChatLog(chatLog, filePath, Options.ExportFormat, Options.PartitionLimit);
|
||||||
|
|
|
@ -9,8 +9,8 @@ namespace DiscordChatExporter.Cli.Verbs.Options
|
||||||
[Option('f', "format", Default = ExportFormat.HtmlDark, HelpText = "Output file format.")]
|
[Option('f', "format", Default = ExportFormat.HtmlDark, HelpText = "Output file format.")]
|
||||||
public ExportFormat ExportFormat { get; set; }
|
public ExportFormat ExportFormat { get; set; }
|
||||||
|
|
||||||
[Option('o', "output", Default = null, HelpText = "Output file path.")]
|
[Option('o', "output", Default = null, HelpText = "Output file or directory path.")]
|
||||||
public string FilePath { get; set; }
|
public string OutputPath { get; set; }
|
||||||
|
|
||||||
[Option("after", Default = null, HelpText = "Limit to messages sent after this date.")]
|
[Option("after", Default = null, HelpText = "Limit to messages sent after this date.")]
|
||||||
public DateTime? After { get; set; }
|
public DateTime? After { get; set; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue