2 feat run parsing folder#29
Conversation
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 17 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| var inputType = FileSystemService.GetInputType(settings.InputPath); | ||
| if (inputType == Enums.InputType.NotSupported) | ||
| { | ||
| AnsiConsole.MarkupLine("[red]Error:[/] Unsupported input type. Please provide a valid directory, AL file, or vscode workspace file."); | ||
| return -1; |
There was a problem hiding this comment.
inputType is an AL2DBML.CLI.Enums.InputType, but the comparison uses Enums.InputType.NotSupported, which won’t resolve from this namespace/import set and should fail to compile. Compare against InputType.NotSupported (add the appropriate using) or fully-qualify AL2DBML.CLI.Enums.InputType.NotSupported.
| // Register services | ||
| var services = new ServiceCollection(); | ||
| services | ||
| .AddAL2Dbml() | ||
| .AddScoped<GenerateCommand>() | ||
| .AddScoped<IParsingTracker, ParsingTracker>(); | ||
|
|
||
| var registrar = new TypeRegistrar(services); | ||
|
|
||
| var app = new CommandApp(registrar); | ||
|
|
||
| app.Configure(config => | ||
| { | ||
| config.AddCommand<GenerateCommand>("generate"); | ||
| }); | ||
|
|
||
| return await app.RunAsync(args); | ||
|
|
||
| public sealed class TypeRegistrar(IServiceCollection services) : ITypeRegistrar | ||
| { | ||
| public ITypeResolver Build() => new TypeResolver(services.BuildServiceProvider()); | ||
|
|
||
| public void Register(Type service, Type implementation) => services.AddScoped(service, implementation); | ||
|
|
||
| public void RegisterInstance(Type service, object implementation) => services.AddSingleton(service, implementation); | ||
|
|
||
| public void RegisterLazy(Type service, Func<object> factory) => services.AddScoped(service, _ => factory()); | ||
| } | ||
|
|
||
| public sealed class TypeResolver(IServiceProvider provider) : ITypeResolver | ||
| { | ||
| public object? Resolve(Type? type) => type == null ? null : provider.GetService(type); | ||
| } |
There was a problem hiding this comment.
DI setup registers several services as AddScoped(...), but TypeRegistrar.Build() builds a root ServiceProvider and TypeResolver.Resolve() pulls services directly from it (no scope created). In Microsoft.Extensions.DependencyInjection this effectively promotes scoped services to root singletons and they won’t be disposed until process exit. Either create a scope per command execution (and resolve from that scope), or switch the relevant registrations to singleton, or use Spectre.Console’s official DI integration to manage scopes/disposal correctly.
| if (!workspaceJson.RootElement.TryGetProperty("folders", out var folders)) | ||
| { | ||
| throw new InvalidDataException("Invalid workspace file: 'folders' property not found."); | ||
| } |
There was a problem hiding this comment.
folders.EnumerateArray() will throw if the workspace JSON has a folders property that isn’t an array (e.g., malformed workspace). Since you’re already validating the schema, consider checking folders.ValueKind == JsonValueKind.Array and throwing a clearer InvalidDataException when it’s not.
| } | |
| } | |
| if (folders.ValueKind != JsonValueKind.Array) | |
| { | |
| throw new InvalidDataException("Invalid workspace file: 'folders' property must be an array."); | |
| } |
Description
This pull request introduces a major refactor and feature expansion to the CLI portion of the project, adding support for parsing different AL input types (directories, single files, and VSCode workspace files) and generating DBML output via a new command-line interface. The changes introduce a strategy pattern for handling input, integrate the Spectre.Console.Cli framework for command parsing, and improve dependency injection and parser state management.
New CLI and Command Framework:
generatecommand that accepts input and output options, and integrates with the application's parsing and DBML writing services. (Program.cs,GenerateCommand.cs,AL2DBML.CLI.csproj) [1] [2] [3]Input Handling and Strategy Pattern:
IInputStrategyand corresponding strategy classes. The correct strategy is selected usingInputStrategyFactory. (IInputStrategy.cs,InputStrategyFactory.cs,FolderInputStrategy.cs,SingleFileInputStrategy.cs,WorkspaceInputStrategy.cs) [1] [2] [3] [4] [5]InputTypeenum andFileSystemServiceto detect and scan input sources. (InputType.cs,FileSystemService.cs) [1] [2]Parser State and Dependency Injection Improvements:
ParserServiceExtensions.cs)ClearOutputSchematoIAlParserand its implementation, allowing parser state to be reset when needed. (IAlParser.cs,AlParser.cs) [1] [2]TestBase.cs)Closes
closes #2
closes #3