Add version verb with option to check for upgrade Add Search verb to search the library Add export file type inference Add more set-status options Add console progress bar and ETA Add processable option to liberate specific book IDs Scan accounts by nickname or account ID Improve startup performance for halp and on parsing error More useful error messages
66 lines
1.9 KiB
C#
66 lines
1.9 KiB
C#
using ApplicationServices;
|
|
using CommandLine;
|
|
using System;
|
|
using System.IO;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace LibationCli
|
|
{
|
|
[Verb("export", HelpText = "Must include path and flag for export file type: --xlsx , --csv , --json")]
|
|
public class ExportOptions : OptionsBase
|
|
{
|
|
[Option(shortName: 'p', longName: "path", Required = true, HelpText = "Path to save file to.")]
|
|
public string FilePath { get; set; }
|
|
|
|
#region explanation of mutually exclusive options
|
|
/*
|
|
giving these SetName values makes them mutually exclusive. they are in different sets. eg:
|
|
class Options
|
|
{
|
|
[Option("username", SetName = "auth")]
|
|
public string Username { get; set; }
|
|
[Option("password", SetName = "auth")]
|
|
public string Password { get; set; }
|
|
|
|
[Option("guestaccess", SetName = "guest")]
|
|
public bool GuestAccess { get; set; }
|
|
}
|
|
*/
|
|
#endregion
|
|
[Option(shortName: 'x', longName: "xlsx", HelpText = "Microsoft Excel Spreadsheet", SetName = "Export Format")]
|
|
public bool xlsx { get; set; }
|
|
|
|
[Option(shortName: 'c', longName: "csv", HelpText = "Comma-separated values", SetName = "Export Format")]
|
|
public bool csv { get; set; }
|
|
|
|
[Option(shortName: 'j', longName: "json", HelpText = "JavaScript Object Notation", SetName = "Export Format")]
|
|
public bool json { get; set; }
|
|
|
|
protected override Task ProcessAsync()
|
|
{
|
|
Action<string> exporter
|
|
= csv ? LibraryExporter.ToCsv
|
|
: json ? LibraryExporter.ToJson
|
|
: xlsx ? LibraryExporter.ToXlsx
|
|
: Path.GetExtension(FilePath)?.ToLower() switch
|
|
{
|
|
".xlsx" => LibraryExporter.ToXlsx,
|
|
".csv" => LibraryExporter.ToCsv,
|
|
".json" => LibraryExporter.ToJson,
|
|
_ => null
|
|
};
|
|
|
|
if (exporter is null)
|
|
{
|
|
PrintVerbUsage($"Undefined export format for file type \"{Path.GetExtension(FilePath)}\"");
|
|
}
|
|
else
|
|
{
|
|
exporter(FilePath);
|
|
Console.WriteLine($"Library exported to: {FilePath}");
|
|
}
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
}
|