mirror of
https://github.com/yaakov-h/Shamir.git
synced 2025-01-18 08:46:33 +00:00
offload subtrees to their own assemblies
This commit is contained in:
parent
81681c35e7
commit
1a3b150b27
4 changed files with 53 additions and 28 deletions
24
src/commands/azure/ServiceCollectionExtensions.cs
Normal file
24
src/commands/azure/ServiceCollectionExtensions.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
22
src/commands/radio/ServiceCollectionExtensions.cs
Normal file
22
src/commands/radio/ServiceCollectionExtensions.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
using System;
|
||||
|
||||
namespace steam
|
||||
{
|
||||
public class Class1
|
||||
{
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
using System.Threading.Tasks;
|
||||
using CommandLine;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Shamir.Abstractions;
|
||||
using Shamir.Commands.Azure;
|
||||
using Shamir.Commands.Radio;
|
||||
|
@ -20,35 +21,21 @@ namespace Shamir.Console
|
|||
with.EnableDashDash = true;
|
||||
with.IgnoreUnknownArguments = false;
|
||||
}))
|
||||
.AddAzureCommandTree()
|
||||
.AddRadioCommandTree()
|
||||
.BuildServiceProvider();
|
||||
|
||||
using var scope = serviceProvider.CreateScope();
|
||||
|
||||
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(),
|
||||
new StorageCopyCommand(),
|
||||
new StorageGetUrlCommand()
|
||||
)),
|
||||
new DefaultCommandTree(
|
||||
"vk",
|
||||
"Australian Amateur Radio commands",
|
||||
ImmutableArray<ICommandTree>.Empty,
|
||||
ImmutableArray.Create<ICommand>(
|
||||
new VKLookupCommand()
|
||||
))
|
||||
),
|
||||
ImmutableArray<ICommand>.Empty
|
||||
scope.ServiceProvider.GetServices<ICommandTree>().ToImmutableArray(),
|
||||
scope.ServiceProvider.GetServices<ICommand>().ToImmutableArray()
|
||||
);
|
||||
|
||||
var command = tree.FindCommand(args);
|
||||
|
||||
using var scope = serviceProvider.CreateScope();
|
||||
return await command.ExecuteAsync(scope.ServiceProvider);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue