OpenAPIClientBuilder/Terminal/Program.cs

42 lines
1.2 KiB
C#
Raw Normal View History

2024-02-17 21:35:45 +00:00
using Cocona;
using Cocona.Application;
using Cocona.Command;
using Cocona.Command.Features;
using Cocona.Help;
using Terminal.Commands;
var builder = CoconaApp.CreateBuilder(args, options =>
{
options.TreatPublicMethodsAsCommands = false;
options.EnableShellCompletionSupport = true;
});
var app = builder.Build();
app.AddCommands<GenerateCommands>();
app.AddCommands<VersionCommands>();
app.AddCommand(PrimaryCommand);
await app.RunAsync();
return;
//
// We define the primary command here, to show our own version information when
// the `--version` option is used, and to show the help index when no option is
// specified.
//
void PrimaryCommand(
bool version,
[FromService] ICoconaAppContextAccessor appContext,
[FromService] ICoconaCommandProvider commandProvider,
[FromService] ICoconaHelpRenderer helpRenderer,
[FromService] ICoconaCommandHelpProvider commandHelpProvider)
{
if (version)
{
VersionCommands.ShowVersion();
return;
}
var commandStack = appContext.Current!.Features.Get<ICoconaCommandFeature>().CommandStack;
Console.Write(helpRenderer.Render(commandHelpProvider.CreateCommandsIndexHelp(commandProvider.GetCommandCollection(), commandStack)));
}