diff --git a/src/commands/azure/ServiceCollectionExtensions.cs b/src/commands/azure/ServiceCollectionExtensions.cs new file mode 100644 index 0000000..424eb17 --- /dev/null +++ b/src/commands/azure/ServiceCollectionExtensions.cs @@ -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(sp => new DefaultCommandTree( + "cdn", + "Browse and add new data to a CDN backed by Azure Storage", + ImmutableArray.Empty, + ImmutableArray.Create( + new StorageLsCommand(), + new StorageCopyCommand(), + new StorageGetUrlCommand() + ))); + + return collection; + } + } +} \ No newline at end of file diff --git a/src/commands/radio/ServiceCollectionExtensions.cs b/src/commands/radio/ServiceCollectionExtensions.cs new file mode 100644 index 0000000..6cc44c9 --- /dev/null +++ b/src/commands/radio/ServiceCollectionExtensions.cs @@ -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(sp => new DefaultCommandTree( + "vk", + "Australian Amateur Radio commands", + ImmutableArray.Empty, + ImmutableArray.Create( + new VKLookupCommand() + ))); + + return collection; + } + } +} \ No newline at end of file diff --git a/src/commands/steam/Class1.cs b/src/commands/steam/Class1.cs deleted file mode 100644 index 3464cfa..0000000 --- a/src/commands/steam/Class1.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System; - -namespace steam -{ - public class Class1 - { - } -} diff --git a/src/console/Program.cs b/src/console/Program.cs index 0a26f1b..ceaa443 100644 --- a/src/console/Program.cs +++ b/src/console/Program.cs @@ -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( - new DefaultCommandTree( - "cdn", - "Browse and add new data to a CDN backed by Azure Storage", - ImmutableArray.Empty, - ImmutableArray.Create( - new StorageLsCommand(), - new StorageCopyCommand(), - new StorageGetUrlCommand() - )), - new DefaultCommandTree( - "vk", - "Australian Amateur Radio commands", - ImmutableArray.Empty, - ImmutableArray.Create( - new VKLookupCommand() - )) - ), - ImmutableArray.Empty + scope.ServiceProvider.GetServices().ToImmutableArray(), + scope.ServiceProvider.GetServices().ToImmutableArray() ); var command = tree.FindCommand(args); - using var scope = serviceProvider.CreateScope(); return await command.ExecuteAsync(scope.ServiceProvider); } }