Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added shortcuts for AaC reader strategies #95

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions C4InterFlow.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,5 @@
context.Add<PublishSiteCommand>();
});

var rootCommand = rootCommandBuilder.Build();

var cliBuilder = new CommandLineBuilder(rootCommand);
var parser = cliBuilder.UseDefaults().UseLogging().Build();
await parser.InvokeAsync(args);
await new CommandLineBuilder(rootCommandBuilder.Build())
.UseDefaults().UseLogging().Build().InvokeAsync(args);
32 changes: 29 additions & 3 deletions C4InterFlow/Cli/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ namespace C4InterFlow.Cli
{
public class Utils
{
private static readonly Dictionary<string, Type> _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<string> ResolveStructures(IEnumerable<string> structures)
{
return AaCReaderContext.Strategy.ResolveStructures(structures);
Expand Down Expand Up @@ -65,21 +81,31 @@ public static void WriteLines(List<string> 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<string, string>());
}

private static Type? GetAaCReaderStrategyType(string readerStrategyType)
{
if (_readerStrategiesMap.TryGetValue(readerStrategyType.ToLowerInvariant(), out var strategyType))
{
return strategyType;
}

return Type.GetType(readerStrategyType);
}
}
}
9 changes: 7 additions & 2 deletions Samples/dotnet.eShop/dotnet.eShop.Architecture.Cli/Program.cs
Original file line number Diff line number Diff line change
@@ -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 =>
{
Expand All @@ -12,4 +16,5 @@
context.Add<ExecuteAaCStrategyCommand>();
});

await root.Run();
await new CommandLineBuilder(rootCommandBuilder.Build())
.UseDefaults().UseLogging().Build().InvokeAsync(args);