Use CliFx for argument parsing in Publish-MacOSBundle.csx

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Tyrrrz/DiscordChatExporter/sessions/4ce0b5aa-af5d-4e9b-9265-2aab165d4b0a
This commit is contained in:
copilot-swe-agent[bot] 2026-03-23 17:36:56 +00:00
parent f5e5eaada7
commit bb87d5cb36

View file

@ -1,21 +1,36 @@
// Publishes the GUI app as a macOS .app bundle. #:package CliFx@2.3.6
// Usage: dotnet run Publish-MacOSBundle.csx -- <PublishDirPath> <IconsFilePath> <FullVersion> <ShortVersion>
if (args.Length < 4) using CliFx;
using CliFx.Attributes;
using CliFx.Infrastructure;
return await new CliApplicationBuilder()
.AddCommand<PublishMacOSBundleCommand>()
.Build()
.RunAsync(args);
[Command(Description = "Publishes the GUI app as a macOS .app bundle.")]
public class PublishMacOSBundleCommand : ICommand
{ {
Console.Error.WriteLine( [CommandParameter(0, Name = "publish-dir", Description = "Path to the publish output directory.")]
"Usage: dotnet run Publish-MacOSBundle.csx -- <PublishDirPath> <IconsFilePath> <FullVersion> <ShortVersion>" public required string PublishDirPath { get; init; }
);
return 1;
}
var publishDirPath = Path.GetFullPath(args[0]); [CommandParameter(1, Name = "icons-file", Description = "Path to the .icns icons file.")]
var iconsFilePath = args[1]; public required string IconsFilePath { get; init; }
var fullVersion = args[2];
var shortVersion = args[3];
[CommandParameter(2, Name = "full-version", Description = "Full version string (e.g. '1.2.3.4').")]
public required string FullVersion { get; init; }
[CommandParameter(3, Name = "short-version", Description = "Short version string (e.g. '1.2.3').")]
public required string ShortVersion { get; init; }
public ValueTask ExecuteAsync(IConsole console)
{
// Setup paths // Setup paths
var tempDirPath = Path.GetFullPath(Path.Combine(publishDirPath, "../publish-macos-app-temp")); var publishDirPath = Path.GetFullPath(PublishDirPath);
var tempDirPath = Path.GetFullPath(
Path.Combine(publishDirPath, "../publish-macos-app-temp")
);
var bundleName = "DiscordChatExporter.app"; var bundleName = "DiscordChatExporter.app";
var bundleDirPath = Path.Combine(tempDirPath, bundleName); var bundleDirPath = Path.Combine(tempDirPath, bundleName);
var contentsDirPath = Path.Combine(bundleDirPath, "Contents"); var contentsDirPath = Path.Combine(bundleDirPath, "Contents");
@ -31,7 +46,11 @@ try
Directory.CreateDirectory(resourcesDirPath); Directory.CreateDirectory(resourcesDirPath);
// Copy icons into the .app's Resources folder // Copy icons into the .app's Resources folder
File.Copy(iconsFilePath, Path.Combine(resourcesDirPath, "AppIcon.icns"), overwrite: true); File.Copy(
IconsFilePath,
Path.Combine(resourcesDirPath, "AppIcon.icns"),
overwrite: true
);
// Generate the Info.plist metadata file with the app information // Generate the Info.plist metadata file with the app information
var plistContent = $""" var plistContent = $"""
@ -56,9 +75,9 @@ try
<key>CFBundleIconName</key> <key>CFBundleIconName</key>
<string>AppIcon</string> <string>AppIcon</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>{fullVersion}</string> <string>{FullVersion}</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>{shortVersion}</string> <string>{ShortVersion}</string>
<key>NSHighResolutionCapable</key> <key>NSHighResolutionCapable</key>
<true /> <true />
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
@ -94,4 +113,6 @@ finally
Directory.Delete(tempDirPath, recursive: true); Directory.Delete(tempDirPath, recursive: true);
} }
return 0; return default;
}
}