diff --git a/C4InterFlow.Cli/Program.cs b/C4InterFlow.Cli/Program.cs index fa0acddec..c2589aadb 100644 --- a/C4InterFlow.Cli/Program.cs +++ b/C4InterFlow.Cli/Program.cs @@ -18,8 +18,5 @@ context.Add(); }); -var rootCommand = rootCommandBuilder.Build(); - -var cliBuilder = new CommandLineBuilder(rootCommand); -var parser = cliBuilder.UseDefaults().UseLogging().Build(); -await parser.InvokeAsync(args); \ No newline at end of file +await new CommandLineBuilder(rootCommandBuilder.Build()) + .UseDefaults().UseLogging().Build().InvokeAsync(args); \ No newline at end of file diff --git a/C4InterFlow/Cli/Utils.cs b/C4InterFlow/Cli/Utils.cs index add938147..988a70ff6 100644 --- a/C4InterFlow/Cli/Utils.cs +++ b/C4InterFlow/Cli/Utils.cs @@ -9,6 +9,22 @@ namespace C4InterFlow.Cli { public class Utils { + private static readonly Dictionary _readerStrategiesMap = new() + { + { + "csharp", + Type.GetType("C4InterFlow.Automation.Readers.CSharpAaCReaderStrategy,C4InterFlow.Automation")! + }, + { + "yaml", + Type.GetType("C4InterFlow.Automation.Readers.YamlAaCReaderStrategy,C4InterFlow.Automation")! + }, + { + "json", + Type.GetType("C4InterFlow.Automation.Readers.JsonAaCReaderStrategy,C4InterFlow.Automation")! + } + }; + public static IEnumerable ResolveStructures(IEnumerable structures) { return AaCReaderContext.Strategy.ResolveStructures(structures); @@ -65,21 +81,31 @@ public static void WriteLines(List items, string filePath, bool append = public static void SetArchitectureAsCodeReaderContext(string[] architectureAsCodeInputPaths, string architectureAsCodeReaderStrategyType) { - Type strategyType = Type.GetType(architectureAsCodeReaderStrategyType); + Type? strategyType = GetAaCReaderStrategyType(architectureAsCodeReaderStrategyType); if (strategyType == null) { throw new ArgumentException($"Cannot load AaC Reader Strategy Type '{architectureAsCodeReaderStrategyType}'"); } + object strategyTypeInstance = Activator.CreateInstance(strategyType); - var strategyInstance = strategyTypeInstance as IAaCReaderStrategy; - if (strategyInstance == null) + if (strategyTypeInstance is not IAaCReaderStrategy strategyInstance) { throw new ArgumentException($"'{architectureAsCodeReaderStrategyType}' is not a valid Architecture As Code Reader Strategy type."); } AaCReaderContext.SetCurrentStrategy(strategyInstance, architectureAsCodeInputPaths, new Dictionary()); } + + private static Type? GetAaCReaderStrategyType(string readerStrategyType) + { + if (_readerStrategiesMap.TryGetValue(readerStrategyType.ToLowerInvariant(), out var strategyType)) + { + return strategyType; + } + + return Type.GetType(readerStrategyType); + } } } diff --git a/Samples/dotnet.eShop/dotnet.eShop.Architecture.Cli/Program.cs b/Samples/dotnet.eShop/dotnet.eShop.Architecture.Cli/Program.cs index e6b8b6a76..f934c4edc 100644 --- a/Samples/dotnet.eShop/dotnet.eShop.Architecture.Cli/Program.cs +++ b/Samples/dotnet.eShop/dotnet.eShop.Architecture.Cli/Program.cs @@ -1,8 +1,12 @@ // See https://aka.ms/new-console-template for more information + +using System.CommandLine.Builder; +using System.CommandLine.Parsing; using C4InterFlow.Cli.Root; using C4InterFlow.Cli.Commands; +using C4InterFlow.Cli.Extensions; -var root = RootCommandBuilder +var rootCommandBuilder = RootCommandBuilder .CreateDefaultBuilder(args) .Configure(context => { @@ -12,4 +16,5 @@ context.Add(); }); -await root.Run(); \ No newline at end of file +await new CommandLineBuilder(rootCommandBuilder.Build()) + .UseDefaults().UseLogging().Build().InvokeAsync(args); \ No newline at end of file