mirror of
https://github.com/yaakov-h/Shamir.git
synced 2025-01-18 16:56: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 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue