Skip to content

Commit

Permalink
Allow changing output file name
Browse files Browse the repository at this point in the history
Closes #398
  • Loading branch information
Deadpikle committed Aug 9, 2024
1 parent 7618046 commit 6190ecb
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
24 changes: 24 additions & 0 deletions src/NetSparkle.Tests.AppCastGenerator/AppCastMakerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
6 changes: 4 additions & 2 deletions src/NetSparkle.Tools.AppCastGenerator/AppCastMaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -425,14 +425,16 @@ public AppCastItem CreateAppCastItemFromFile(FileInfo binaryFileInfo, string? pr
/// </summary>
/// <param name="desiredOutputDirectory"></param>
/// <param name="sourceBinaryDirectory"></param>
/// <param name="appCastFileName">file name for output w/o extension or . for extension</param>
/// <returns></returns>
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());
}

/// <summary>
Expand Down
5 changes: 5 additions & 0 deletions src/NetSparkle.Tools.AppCastGenerator/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
6 changes: 5 additions & 1 deletion src/NetSparkle.Tools.AppCastGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down

0 comments on commit 6190ecb

Please sign in to comment.