From 6190ecbdfa0d8c1cdcbed18e0f3a1049323d1873 Mon Sep 17 00:00:00 2001 From: Michael Babienco Date: Fri, 9 Aug 2024 17:32:08 +0900 Subject: [PATCH] Allow changing output file name Closes #398 --- .../AppCastMakerTests.cs | 24 +++++++++++++++++++ .../AppCastMaker.cs | 6 +++-- .../Options.cs | 5 ++++ .../Program.cs | 6 ++++- 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/NetSparkle.Tests.AppCastGenerator/AppCastMakerTests.cs b/src/NetSparkle.Tests.AppCastGenerator/AppCastMakerTests.cs index 94864a14..c96e459d 100644 --- a/src/NetSparkle.Tests.AppCastGenerator/AppCastMakerTests.cs +++ b/src/NetSparkle.Tests.AppCastGenerator/AppCastMakerTests.cs @@ -958,6 +958,30 @@ public void CanSetVersionViaCLI() } } + [Fact] + public void CanSetOutputFileNameViaCLI() + { + var opts = new Options() + { + Extensions = "txt", + OutputDirectory = ".", + OperatingSystem = "windows", + BaseUrl = "https://example.com/downloads", + OutputFileName = "we-like-files" + }; + + var signatureManager = _fixture.GetSignatureManager(); + Assert.True(signatureManager.KeysExist()); + + var maker = new XMLAppCastMaker(signatureManager, opts); + // no file name sent should default to "appcast" + var appCastFileName = maker.GetPathToAppCastOutput(opts.OutputDirectory, opts.SourceBinaryDirectory); + Assert.Contains("appcast", appCastFileName); + // sending file name changes output + appCastFileName = maker.GetPathToAppCastOutput(opts.OutputDirectory, opts.SourceBinaryDirectory, opts.OutputFileName); + Assert.Contains("we-like-files", appCastFileName); + } + [Theory] [InlineData(AppCastMakerType.Xml)] [InlineData(AppCastMakerType.Json)] diff --git a/src/NetSparkle.Tools.AppCastGenerator/AppCastMaker.cs b/src/NetSparkle.Tools.AppCastGenerator/AppCastMaker.cs index 7bd9ff7e..1c7ed5b3 100644 --- a/src/NetSparkle.Tools.AppCastGenerator/AppCastMaker.cs +++ b/src/NetSparkle.Tools.AppCastGenerator/AppCastMaker.cs @@ -425,14 +425,16 @@ public AppCastItem CreateAppCastItemFromFile(FileInfo binaryFileInfo, string? pr /// /// /// + /// file name for output w/o extension or . for extension /// - public string GetPathToAppCastOutput(string desiredOutputDirectory, string sourceBinaryDirectory) + public string GetPathToAppCastOutput(string desiredOutputDirectory, string sourceBinaryDirectory, string appCastFileName = "appcast") { if (string.IsNullOrWhiteSpace(desiredOutputDirectory)) { desiredOutputDirectory = sourceBinaryDirectory; } - return Path.Combine(desiredOutputDirectory, "appcast." + GetAppCastExtension()); + return Path.Combine(desiredOutputDirectory, + appCastFileName.Trim().Trim('.') + "." + GetAppCastExtension()); } /// diff --git a/src/NetSparkle.Tools.AppCastGenerator/Options.cs b/src/NetSparkle.Tools.AppCastGenerator/Options.cs index 14356ed3..b4e82f81 100644 --- a/src/NetSparkle.Tools.AppCastGenerator/Options.cs +++ b/src/NetSparkle.Tools.AppCastGenerator/Options.cs @@ -68,6 +68,11 @@ public class Options Default = "signature")] public string? SignatureFileExtension { get; set; } + [Option("output-file-name", SetName = "local", Required = false, + HelpText = "Output file name without the . or extension. Extension is controlled by whether it is an xml or json output and is not configurable. Defaults to 'appcast'. Of course, you can always change this later on your own; this option is only for convenience.", + Default = "appcast")] + public string? OutputFileName { get; set; } + [Option("use-ed25519-signature-attribute", SetName = "local", Required = false, HelpText = "If true and doing XML output, the output signature attribute in the XML will be 'edSignature' rather than 'signature' to match the original Sparkle library.", Default = "signature")] diff --git a/src/NetSparkle.Tools.AppCastGenerator/Program.cs b/src/NetSparkle.Tools.AppCastGenerator/Program.cs index 11af9b14..36f08fd2 100644 --- a/src/NetSparkle.Tools.AppCastGenerator/Program.cs +++ b/src/NetSparkle.Tools.AppCastGenerator/Program.cs @@ -114,7 +114,11 @@ static void Run(Options opts) AppCastMaker generator = opts.OutputType?.ToLower() != "json" ? new XMLAppCastMaker(signatureManager, opts) : new JsonAppCastMaker(signatureManager, opts); - var appCastFileName = generator.GetPathToAppCastOutput(opts.OutputDirectory ?? ".", opts.SourceBinaryDirectory ?? "."); + var appCastFileName = generator.GetPathToAppCastOutput( + opts.OutputDirectory ?? ".", + opts.SourceBinaryDirectory ?? ".", + opts.OutputFileName ?? "appcast" + ); var outputDirName = Path.GetDirectoryName(appCastFileName); if (outputDirName == null || string.IsNullOrWhiteSpace(outputDirName)) {