diff --git a/EnvelopeGenerator.Terminal/CommandManager.cs b/EnvelopeGenerator.Terminal/CommandManager.cs new file mode 100644 index 00000000..40a22a86 --- /dev/null +++ b/EnvelopeGenerator.Terminal/CommandManager.cs @@ -0,0 +1,14 @@ +using CommandDotNet; +using System.Reflection; + +namespace EnvelopeGenerator.Terminal; + +public class CommandManager +{ + [DefaultCommand] + public void Execute([Option(Description = "print envelope generator termianal version.")] bool version) + { + if(version) + Console.WriteLine($"v{Assembly.GetExecutingAssembly().GetName().Version}"); + } +} diff --git a/EnvelopeGenerator.Terminal/DependencyInjection.cs b/EnvelopeGenerator.Terminal/DependencyInjection.cs new file mode 100644 index 00000000..e28696c7 --- /dev/null +++ b/EnvelopeGenerator.Terminal/DependencyInjection.cs @@ -0,0 +1,28 @@ +using CommandDotNet.NameCasing; +using CommandDotNet; +using Microsoft.Extensions.DependencyInjection; +using CommandDotNet.IoC.MicrosoftDependencyInjection; + +namespace EnvelopeGenerator.Terminal; + +public static class DependencyInjection +{ + public static IServiceCollection AddCommandManagerRunner(this IServiceCollection services, Case @case = Case.KebabCase) + { + return services + .AddSingleton() + .AddSingleton(sp => + { + var runner = new AppRunner(); + runner.UseMicrosoftDependencyInjection(sp); + runner.UseNameCasing(@case); + return runner; + }); + } + + public static Task RunCommandManagerRunner(this IServiceProvider provider, string[] args) + { + var runner = provider.GetRequiredService>(); + return runner.RunAsync(args); + } +} diff --git a/EnvelopeGenerator.Terminal/EnvelopeGenerator.Terminal.csproj b/EnvelopeGenerator.Terminal/EnvelopeGenerator.Terminal.csproj new file mode 100644 index 00000000..3fa95dea --- /dev/null +++ b/EnvelopeGenerator.Terminal/EnvelopeGenerator.Terminal.csproj @@ -0,0 +1,23 @@ + + + + Exe + net8.0 + enable + enable + true + true + + + + + + + + + + + + + + diff --git a/EnvelopeGenerator.Terminal/Program.cs b/EnvelopeGenerator.Terminal/Program.cs new file mode 100644 index 00000000..b978cf04 --- /dev/null +++ b/EnvelopeGenerator.Terminal/Program.cs @@ -0,0 +1,17 @@ +using Microsoft.Extensions.Hosting; + +namespace EnvelopeGenerator.Terminal; + +public class Program +{ + static async Task Main(string[] args) + { + var builder = Host.CreateApplicationBuilder(args); + + builder.Services.AddCommandManagerRunner(); + + var app = builder.Build(); + + return await app.Services.RunCommandManagerRunner(args); + } +} \ No newline at end of file diff --git a/EnvelopeGenerator.sln b/EnvelopeGenerator.sln index 0275e352..4c8aa8c9 100644 --- a/EnvelopeGenerator.sln +++ b/EnvelopeGenerator.sln @@ -35,6 +35,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "infrastructure", "infrastru EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "presentation", "presentation", "{E3C758DC-914D-4B7E-8457-0813F1FDB0CB}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EnvelopeGenerator.Terminal", "EnvelopeGenerator.Terminal\EnvelopeGenerator.Terminal.csproj", "{A9F9B431-BB9B-49B8-9E2C-0703634A653A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -85,6 +87,10 @@ Global {A4D0DD1A-67BC-4E1A-AD29-BC4BC0D41399}.Debug|Any CPU.Build.0 = Debug|Any CPU {A4D0DD1A-67BC-4E1A-AD29-BC4BC0D41399}.Release|Any CPU.ActiveCfg = Release|Any CPU {A4D0DD1A-67BC-4E1A-AD29-BC4BC0D41399}.Release|Any CPU.Build.0 = Release|Any CPU + {A9F9B431-BB9B-49B8-9E2C-0703634A653A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A9F9B431-BB9B-49B8-9E2C-0703634A653A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A9F9B431-BB9B-49B8-9E2C-0703634A653A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A9F9B431-BB9B-49B8-9E2C-0703634A653A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -104,6 +110,7 @@ Global {A4D0DD1A-67BC-4E1A-AD29-BC4BC0D41399} = {0CBC2432-A561-4440-89BC-671B66A24146} {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} = {134D4164-B291-4E19-99B9-E4FA3AFAB62C} {E3C758DC-914D-4B7E-8457-0813F1FDB0CB} = {134D4164-B291-4E19-99B9-E4FA3AFAB62C} + {A9F9B431-BB9B-49B8-9E2C-0703634A653A} = {E3C758DC-914D-4B7E-8457-0813F1FDB0CB} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {73E60370-756D-45AD-A19A-C40A02DACCC7}