Moved the build script to System.CommandLine (#1159)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-11-04 14:57:37 +01:00
1 parent f0fa1411c8
commit 54c3f0b3e0
12 files changed
+232 -70

No files matched your search

+45 -11
View File
@@ -1,12 +1,46 @@
using Build.Commands;
using System.CommandLine.Help;
var builder = CoconaApp.CreateBuilder();
var app = builder.Build();
app.AddCommands<CheckRidsCommand>();
app.AddCommands<UpdateMetadataCommands>();
app.AddCommands<UpdateWebAssetsCommand>();
app.AddCommands<CollectI18NKeysCommand>();
app.AddCommands<AssistantPluginHashCommand>();
app.AddCommands<VerifyModelsCommand>();
app.AddCommands<VerifyCommand>();
app.Run();
using Build.Commands;
using Build.Tools;
//
// A RootCommand would take the name of the executable, which is "build", and System.CommandLine refuses
// a root with the same name as one of its commands. Hence, the root is a command of its own, which
// brings only the help option of a RootCommand along:
//
var rootCommand = new Command("build-script", "Build, check, and release MindWork AI Studio. Run the commands from app/Build with 'dotnet run <command>'.")
{
new HelpOption(),
CheckRidsCommand.CreateCommand(),
UpdateMetadataCommands.CreateReleaseCommand(),
UpdateMetadataCommands.CreateRebuildReleaseCommand(),
UpdateMetadataCommands.CreateUpdateMetainfoCommand(),
UpdateMetadataCommands.CreateUpdateVersionsCommand(),
UpdateMetadataCommands.CreatePrepareCommand(),
UpdateMetadataCommands.CreateBuildCommand(),
UpdateMetadataCommands.CreateUpdateProjectHashCommand(),
UpdateWebAssetsCommand.CreateCommand(),
CollectI18NKeysCommand.CreateCommand(),
AssistantPluginHashCommand.CreateCommand(),
VerifyModelsCommand.CreateCommand(),
VerifyCommand.CreateCommand()
};
//
// A command which fails deep inside, e.g., the build within a release, ends the whole script through
// a CommandExitedException, once it has said why. System.CommandLine would print that exception with
// its stack trace, so we handle the exceptions ourselves and print only those nobody expected:
//
try
{
return await rootCommand.Parse(args).InvokeAsync(new InvocationConfiguration { EnableDefaultExceptionHandler = false });
}
catch (CommandExitedException exception)
{
return exception.ExitCode;
}
catch (Exception exception)
{
Console.Error.WriteLine($"Unhandled exception: {exception}");
return 1;
}