2026-11-04 14:57:37 +01:00
using System.CommandLine.Help ;
2025-04-14 19:29:56 +02:00
2026-11-04 14:57:37 +01:00
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:
//
2026-11-23 11:07:50 +01:00
var rootCommand = new Command ( "build-script" , "Build, check, and release MindWork AI Studio. Run the commands from app/Build with 'dotnet run -- <command>'." )
2026-11-04 14:57:37 +01:00
{
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 (),
2026-11-23 09:46:12 +01:00
VerifyCommand . CreateCommand (),
FlatpakCommand . CreateCommand ()
2026-11-04 14:57:37 +01:00
};
//
// 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
2026-11-23 09:46:12 +01:00
// its stack trace, so we handle the exceptions ourselves and print only those nobody expected.
//
// System.CommandLine would also answer Ctrl+C by cancelling a token and ending the script two seconds
// later, whether the command has finished or not. No command reads that token, and the command flatpak
// needs longer to remove its container and volume. Without the timeout, Ctrl+C ends a command at once,
// unless the command handles Ctrl+C itself, as flatpak does:
2026-11-04 14:57:37 +01:00
//
try
{
2026-11-23 09:46:12 +01:00
return await rootCommand . Parse ( args ). InvokeAsync ( new InvocationConfiguration { EnableDefaultExceptionHandler = false , ProcessTerminationTimeout = null });
2026-11-04 14:57:37 +01:00
}
catch ( CommandExitedException exception )
{
return exception . ExitCode ;
}
catch ( Exception exception )
{
Console . Error . WriteLine ( $"Unhandled exception: {exception}" );
return 1 ;
}