offload subtrees to their own assemblies

This commit is contained in:
Yaakov 2021-09-30 20:01:03 +10:00
parent 81681c35e7
commit 1a3b150b27
4 changed files with 53 additions and 28 deletions

View file

@ -0,0 +1,24 @@
using System.Collections.Immutable;
using Microsoft.Extensions.DependencyInjection;
using Shamir.Abstractions;
namespace Shamir.Commands.Azure
{
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddAzureCommandTree(this IServiceCollection collection)
{
collection.AddTransient<ICommandTree>(sp => new DefaultCommandTree(
"cdn",
"Browse and add new data to a CDN backed by Azure Storage",
ImmutableArray<ICommandTree>.Empty,
ImmutableArray.Create<ICommand>(
new StorageLsCommand(),
new StorageCopyCommand(),
new StorageGetUrlCommand()
)));
return collection;
}
}
}

View file

@ -0,0 +1,22 @@
using System.Collections.Immutable;
using Microsoft.Extensions.DependencyInjection;
using Shamir.Abstractions;
namespace Shamir.Commands.Radio
{
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddRadioCommandTree(this IServiceCollection collection)
{
collection.AddTransient<ICommandTree>(sp => new DefaultCommandTree(
"vk",
"Australian Amateur Radio commands",
ImmutableArray<ICommandTree>.Empty,
ImmutableArray.Create<ICommand>(
new VKLookupCommand()
)));
return collection;
}
}
}

View file

@ -1,8 +0,0 @@
using System;
namespace steam
{
public class Class1
{
}
}

View file

@ -2,6 +2,7 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using CommandLine; using CommandLine;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Shamir.Abstractions; using Shamir.Abstractions;
using Shamir.Commands.Azure; using Shamir.Commands.Azure;
using Shamir.Commands.Radio; using Shamir.Commands.Radio;
@ -20,35 +21,21 @@ namespace Shamir.Console
with.EnableDashDash = true; with.EnableDashDash = true;
with.IgnoreUnknownArguments = false; with.IgnoreUnknownArguments = false;
})) }))
.AddAzureCommandTree()
.AddRadioCommandTree()
.BuildServiceProvider(); .BuildServiceProvider();
using var scope = serviceProvider.CreateScope();
var tree = new DefaultCommandTree( var tree = new DefaultCommandTree(
"shamir", "shamir",
"command-line multitool", "command-line multitool",
ImmutableArray.Create<ICommandTree>( scope.ServiceProvider.GetServices<ICommandTree>().ToImmutableArray(),
new DefaultCommandTree( scope.ServiceProvider.GetServices<ICommand>().ToImmutableArray()
"cdn",
"Browse and add new data to a CDN backed by Azure Storage",
ImmutableArray<ICommandTree>.Empty,
ImmutableArray.Create<ICommand>(
new StorageLsCommand(),
new StorageCopyCommand(),
new StorageGetUrlCommand()
)),
new DefaultCommandTree(
"vk",
"Australian Amateur Radio commands",
ImmutableArray<ICommandTree>.Empty,
ImmutableArray.Create<ICommand>(
new VKLookupCommand()
))
),
ImmutableArray<ICommand>.Empty
); );
var command = tree.FindCommand(args); var command = tree.FindCommand(args);
using var scope = serviceProvider.CreateScope();
return await command.ExecuteAsync(scope.ServiceProvider); return await command.ExecuteAsync(scope.ServiceProvider);
} }
} }