Shamir/src/console/Program.cs

45 lines
1.5 KiB
C#
Raw Normal View History

2021-09-25 23:29:46 +10:00
using System.Collections.Immutable;
2021-09-25 23:04:18 +10:00
using System.Threading.Tasks;
using CommandLine;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
2021-09-30 19:52:25 +10:00
using Shamir.Abstractions;
using Shamir.Commands.Azure;
using Shamir.Commands.Radio;
2021-09-25 23:04:18 +10:00
namespace Shamir.Console
{
2021-09-25 23:29:46 +10:00
public static class Program
2021-09-25 23:04:18 +10:00
{
2021-09-25 23:29:46 +10:00
public static async Task<int> Main(string[] args)
2021-09-25 23:04:18 +10:00
{
await using var serviceProvider = new ServiceCollection()
.AddTransient<Parser>(sp => new Parser(with =>
{
with.AutoHelp = true;
with.AutoVersion = true;
with.EnableDashDash = true;
with.IgnoreUnknownArguments = false;
}))
.AddSingleton<IConsole, SystemConsole>()
.AddAzureCommandTree()
.AddRadioCommandTree()
2021-09-30 20:10:35 +10:00
.AddSteamCommandTree()
.BuildServiceProvider();
using var scope = serviceProvider.CreateScope();
2021-09-25 23:29:46 +10:00
var tree = new DefaultCommandTree(
"shamir",
"command-line multitool",
scope.ServiceProvider.GetServices<ICommandTree>().ToImmutableArray(),
scope.ServiceProvider.GetServices<ICommand>().ToImmutableArray()
2021-09-25 23:04:18 +10:00
);
var command = tree.FindCommand(args);
return await command.ExecuteAsync(scope.ServiceProvider);
2021-09-25 23:04:18 +10:00
}
}
}