implement "cdn ls" via CommandLineParser

This commit is contained in:
Yaakov 2021-09-26 00:07:48 +10:00
parent 74c7070e38
commit a4f9f13780
7 changed files with 113 additions and 8 deletions

View file

@ -1,5 +1,7 @@
using System.Collections.Immutable;
using System.Threading.Tasks;
using CommandLine;
using Microsoft.Extensions.DependencyInjection;
namespace Shamir.Console
{
@ -7,19 +9,29 @@ namespace Shamir.Console
{
public static async Task<int> Main(string[] args)
{
await using var serviceProvider = new ServiceCollection()
.AddTransient<Parser>(sp => new Parser(with => with.EnableDashDash = true))
.BuildServiceProvider();
var tree = new DefaultCommandTree(
"shamir",
"command-line multitool",
ImmutableArray.Create<ICommandTree>(
new DefaultCommandTree(
"cdn",
"Browse and add new data to a CDN backed by Azure Storage",
ImmutableArray<ICommandTree>.Empty,
ImmutableArray.Create<ICommand>(
new StorageLsCommand()
))
),
ImmutableArray.Create<ICommand>(
)
ImmutableArray<ICommand>.Empty
);
var command = tree.FindCommand(args);
return await command.ExecuteAsync();
using var scope = serviceProvider.CreateScope();
return await command.ExecuteAsync(scope.ServiceProvider);
}
}
}