Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
namespace GenAIDBExplorer.Console.CommandHandlers;

/// <summary>
/// Abstract base class for command handlers.
/// Abstract base class for command handlers using System.CommandLine 2.0.0-beta5 API patterns.
/// </summary>
/// <remarks>
/// This class provides common utility functionality for handling console commands.
/// With System.CommandLine beta5, command handlers use ParseResult parameters
/// and SetAction methods instead of the previous SetHandler patterns.
/// </remarks>
/// <remarks>
/// Initializes a new instance of the <see cref="CommandHandler"/> class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ILogger<ICommandHandler<DataDictionaryCommandHandlerOptions>> logger
private readonly IDataDictionaryProvider _dataDictionaryProvider = serviceProvider.GetRequiredService<IDataDictionaryProvider>();

/// <summary>
/// Sets up the data-dictionary command.
/// Sets up the data-dictionary command using System.CommandLine 2.0.0-beta5 API patterns.
/// </summary>
/// <param name="host">The host instance.</param>
/// <returns>The data-dictionary command.</returns>
Expand All @@ -51,31 +51,31 @@ public static Command SetupCommand(IHost host)
description: "The path to the GenAI Database Explorer project."
)
{
IsRequired = true
Required = true // Updated from IsRequired for beta5 compatibility
};

var sourcePathOption = new Option<string>(
aliases: ["--source-path", "-d"],
description: "The path to the source directory containing data dictionary files. Supports file masks."
)
{
IsRequired = true
Required = true // Updated from IsRequired for beta5 compatibility
};

var schemaNameOption = new Option<string>(
aliases: ["--schema", "-s"],
description: "The schema name of the object to process."
)
{
ArgumentHelpName = "schemaName"
HelpName = "schemaName" // Updated from ArgumentHelpName for beta5 compatibility
};

var nameOption = new Option<string>(
aliases: ["--name", "-n"],
description: "The name of the object to process."
)
{
ArgumentHelpName = "name"
HelpName = "name" // Updated from ArgumentHelpName for beta5 compatibility
};

var showOption = new Option<bool>(
Expand All @@ -84,21 +84,24 @@ public static Command SetupCommand(IHost host)
getDefaultValue: () => false
);

var dataDictionaryCommand = new Command("data-dictionary", "Process data dictionary files and update the semantic model.")
{
projectPathOption
};

var tableCommand = new Command("table", "Process table data dictionary files.")
{
projectPathOption,
sourcePathOption,
schemaNameOption,
nameOption,
showOption
};
tableCommand.SetHandler(async (DirectoryInfo projectPath, string sourcePathPattern, string schemaName, string name, bool show) =>
var dataDictionaryCommand = new Command("data-dictionary", "Process data dictionary files and update the semantic model.");
dataDictionaryCommand.Options.Add(projectPathOption); // Updated from AddOption for beta5 compatibility

var tableCommand = new Command("table", "Process table data dictionary files.");
tableCommand.Options.Add(projectPathOption);
tableCommand.Options.Add(sourcePathOption);
tableCommand.Options.Add(schemaNameOption);
tableCommand.Options.Add(nameOption);
tableCommand.Options.Add(showOption);

tableCommand.SetAction(async (ParseResult parseResult) => // Updated from SetHandler for beta5 compatibility
{
var projectPath = parseResult.GetValue(projectPathOption);
var sourcePathPattern = parseResult.GetValue(sourcePathOption);
var schemaName = parseResult.GetValue(schemaNameOption);
var name = parseResult.GetValue(nameOption);
var show = parseResult.GetValue(showOption);

var handler = host.Services.GetRequiredService<DataDictionaryCommandHandler>();
var options = new DataDictionaryCommandHandlerOptions(
projectPath,
Expand All @@ -109,9 +112,9 @@ public static Command SetupCommand(IHost host)
show: show
);
await handler.HandleAsync(options);
}, projectPathOption, sourcePathOption, schemaNameOption, nameOption, showOption);
});

dataDictionaryCommand.AddCommand(tableCommand);
dataDictionaryCommand.Subcommands.Add(tableCommand); // Updated from AddCommand for beta5 compatibility

return dataDictionaryCommand;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ILogger<ICommandHandler<EnrichModelCommandHandlerOptions>> logger
private readonly ISemanticDescriptionProvider _semanticDescriptionProvider = serviceProvider.GetRequiredService<ISemanticDescriptionProvider>();

/// <summary>
/// Sets up the enrich-model command.
/// Sets up the enrich-model command using System.CommandLine 2.0.0-beta5 API patterns.
/// </summary>
/// <param name="host">The host instance.</param>
/// <returns>The enrich-model command.</returns>
Expand All @@ -45,7 +45,7 @@ public static Command SetupCommand(IHost host)
description: "The path to the GenAI Database Explorer project."
)
{
IsRequired = true
Required = true // Updated from IsRequired for beta5 compatibility
};

var skipTablesOption = new Option<bool>(
Expand All @@ -71,15 +71,15 @@ public static Command SetupCommand(IHost host)
description: "The schema name of the object to enrich."
)
{
ArgumentHelpName = "schemaName"
HelpName = "schemaName" // Updated from ArgumentHelpName for beta5 compatibility
};

var nameOption = new Option<string>(
aliases: ["--name", "-n"],
description: "The name of the object to enrich."
)
{
ArgumentHelpName = "name"
HelpName = "name" // Updated from ArgumentHelpName for beta5 compatibility
};

var showOption = new Option<bool>(
Expand All @@ -88,25 +88,27 @@ public static Command SetupCommand(IHost host)
getDefaultValue: () => false
);

// Create the base 'enrich-model' command
var enrichModelCommand = new Command("enrich-model", "Enrich an existing semantic model with descriptions in a GenAI Database Explorer project.")
{
projectPathOption,
skipTablesOption,
skipViewsOption,
skipStoredProceduresOption
};
// Create the base 'enrich-model' command with beta5 mutable collections API
var enrichModelCommand = new Command("enrich-model", "Enrich an existing semantic model with descriptions in a GenAI Database Explorer project.");
enrichModelCommand.Options.Add(projectPathOption); // Updated from AddOption for beta5 compatibility
enrichModelCommand.Options.Add(skipTablesOption);
enrichModelCommand.Options.Add(skipViewsOption);
enrichModelCommand.Options.Add(skipStoredProceduresOption);

// Create subcommands
var tableCommand = new Command("table", "Enrich a specific table.")
{
projectPathOption,
schemaNameOption,
nameOption,
showOption
};
tableCommand.SetHandler(async (DirectoryInfo projectPath, string schemaName, string name, bool show) =>
var tableCommand = new Command("table", "Enrich a specific table.");
tableCommand.Options.Add(projectPathOption);
tableCommand.Options.Add(schemaNameOption);
tableCommand.Options.Add(nameOption);
tableCommand.Options.Add(showOption);

tableCommand.SetAction(async (ParseResult parseResult) => // Updated from SetHandler for beta5 compatibility
{
var projectPath = parseResult.GetValue(projectPathOption);
var schemaName = parseResult.GetValue(schemaNameOption);
var name = parseResult.GetValue(nameOption);
var show = parseResult.GetValue(showOption);

var handler = host.Services.GetRequiredService<EnrichModelCommandHandler>();
var options = new EnrichModelCommandHandlerOptions(
projectPath,
Expand All @@ -119,17 +121,21 @@ public static Command SetupCommand(IHost host)
show: show
);
await handler.HandleAsync(options);
}, projectPathOption, schemaNameOption, nameOption, showOption);
});

var viewCommand = new Command("view", "Enrich a specific view.")
{
projectPathOption,
schemaNameOption,
nameOption,
showOption
};
viewCommand.SetHandler(async (DirectoryInfo projectPath, string schemaName, string name, bool show) =>
var viewCommand = new Command("view", "Enrich a specific view.");
viewCommand.Options.Add(projectPathOption);
viewCommand.Options.Add(schemaNameOption);
viewCommand.Options.Add(nameOption);
viewCommand.Options.Add(showOption);

viewCommand.SetAction(async (ParseResult parseResult) => // Updated from SetHandler for beta5 compatibility
{
var projectPath = parseResult.GetValue(projectPathOption);
var schemaName = parseResult.GetValue(schemaNameOption);
var name = parseResult.GetValue(nameOption);
var show = parseResult.GetValue(showOption);

var handler = host.Services.GetRequiredService<EnrichModelCommandHandler>();
var options = new EnrichModelCommandHandlerOptions(
projectPath,
Expand All @@ -142,17 +148,21 @@ public static Command SetupCommand(IHost host)
show: show
);
await handler.HandleAsync(options);
}, projectPathOption, schemaNameOption, nameOption, showOption);
});

var storedProcedureCommand = new Command("storedprocedure", "Enrich a specific stored procedure.")
{
projectPathOption,
schemaNameOption,
nameOption,
showOption
};
storedProcedureCommand.SetHandler(async (DirectoryInfo projectPath, string schemaName, string name, bool show) =>
var storedProcedureCommand = new Command("storedprocedure", "Enrich a specific stored procedure.");
storedProcedureCommand.Options.Add(projectPathOption);
storedProcedureCommand.Options.Add(schemaNameOption);
storedProcedureCommand.Options.Add(nameOption);
storedProcedureCommand.Options.Add(showOption);

storedProcedureCommand.SetAction(async (ParseResult parseResult) => // Updated from SetHandler for beta5 compatibility
{
var projectPath = parseResult.GetValue(projectPathOption);
var schemaName = parseResult.GetValue(schemaNameOption);
var name = parseResult.GetValue(nameOption);
var show = parseResult.GetValue(showOption);

var handler = host.Services.GetRequiredService<EnrichModelCommandHandler>();
var options = new EnrichModelCommandHandlerOptions(
projectPath,
Expand All @@ -165,20 +175,25 @@ public static Command SetupCommand(IHost host)
show: show
);
await handler.HandleAsync(options);
}, projectPathOption, schemaNameOption, nameOption, showOption);
});

// Add subcommands to the 'enrich-model' command
enrichModelCommand.AddCommand(tableCommand);
enrichModelCommand.AddCommand(viewCommand);
enrichModelCommand.AddCommand(storedProcedureCommand);
// Add subcommands to the 'enrich-model' command using beta5 mutable collections API
enrichModelCommand.Subcommands.Add(tableCommand); // Updated from AddCommand for beta5 compatibility
enrichModelCommand.Subcommands.Add(viewCommand);
enrichModelCommand.Subcommands.Add(storedProcedureCommand);

// Set default handler if no subcommand is provided
enrichModelCommand.SetHandler(async (DirectoryInfo projectPath, bool skipTables, bool skipViews, bool skipStoredProcedures) =>
enrichModelCommand.SetAction(async (ParseResult parseResult) => // Updated from SetHandler for beta5 compatibility
{
var projectPath = parseResult.GetValue(projectPathOption);
var skipTables = parseResult.GetValue(skipTablesOption);
var skipViews = parseResult.GetValue(skipViewsOption);
var skipStoredProcedures = parseResult.GetValue(skipStoredProceduresOption);

var handler = host.Services.GetRequiredService<EnrichModelCommandHandler>();
var options = new EnrichModelCommandHandlerOptions(projectPath, skipTables, skipViews, skipStoredProcedures);
await handler.HandleAsync(options);
}, projectPathOption, skipTablesOption, skipViewsOption, skipStoredProceduresOption);
});

return enrichModelCommand;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ILogger<ICommandHandler<ExportModelCommandHandlerOptions>> logger
}

/// <summary>
/// Sets up the export-model command.
/// Sets up the export-model command using System.CommandLine 2.0.0-beta5 API patterns.
/// </summary>
/// <param name="host">The host instance.</param>
/// <returns>The export-model command.</returns>
Expand All @@ -52,7 +52,7 @@ public static Command SetupCommand(IHost host)
description: "The path to the GenAI Database Explorer project."
)
{
IsRequired = true
Required = true // Updated from IsRequired for beta5 compatibility
};

var outputFileNameOption = new Option<string?>(
Expand All @@ -73,17 +73,22 @@ public static Command SetupCommand(IHost host)
);

var exportModelCommand = new Command("export-model", "Export the semantic model from a GenAI Database Explorer project.");
exportModelCommand.AddOption(projectPathOption);
exportModelCommand.AddOption(outputFileNameOption);
exportModelCommand.AddOption(fileTypeOption);
exportModelCommand.AddOption(splitFilesOption);
exportModelCommand.Options.Add(projectPathOption); // Updated from AddOption for beta5 compatibility
exportModelCommand.Options.Add(outputFileNameOption);
exportModelCommand.Options.Add(fileTypeOption);
exportModelCommand.Options.Add(splitFilesOption);

exportModelCommand.SetHandler(async (DirectoryInfo projectPath, string? outputFileName, string fileType, bool splitFiles) =>
exportModelCommand.SetAction(async (ParseResult parseResult) => // Updated from SetHandler for beta5 compatibility
{
var projectPath = parseResult.GetValue(projectPathOption);
var outputFileName = parseResult.GetValue(outputFileNameOption);
var fileType = parseResult.GetValue(fileTypeOption);
var splitFiles = parseResult.GetValue(splitFilesOption);

var handler = host.Services.GetRequiredService<ExportModelCommandHandler>();
var options = new ExportModelCommandHandlerOptions(projectPath, outputFileName, fileType, splitFiles);
await handler.HandleAsync(options);
}, projectPathOption, outputFileNameOption, fileTypeOption, splitFilesOption);
});

return exportModelCommand;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ILogger<ICommandHandler<ExtractModelCommandHandlerOptions>> logger
private static readonly ResourceManager _resourceManagerLogMessages = new("GenAIDBExplorer.Console.Resources.LogMessages", typeof(ExtractModelCommandHandler).Assembly);

/// <summary>
/// Sets up the extract model command.
/// Sets up the extract model command using System.CommandLine 2.0.0-beta5 API patterns.
/// </summary>
/// <param name="host">The host instance.</param>
/// <returns>The extract model command.</returns>
Expand All @@ -44,7 +44,7 @@ public static Command SetupCommand(IHost host)
description: "The path to the GenAI Database Explorer project."
)
{
IsRequired = true
Required = true // Updated from IsRequired for beta5 compatibility
};

var skipTablesOption = new Option<bool>(
Expand All @@ -66,16 +66,22 @@ public static Command SetupCommand(IHost host)
);

var extractModelCommand = new Command("extract-model", "Extract a semantic model from a SQL database for a GenAI Database Explorer project.");
extractModelCommand.AddOption(projectPathOption);
extractModelCommand.AddOption(skipTablesOption);
extractModelCommand.AddOption(skipViewsOption);
extractModelCommand.AddOption(skipStoredProceduresOption);
extractModelCommand.SetHandler(async (DirectoryInfo projectPath, bool skipTables, bool skipViews, bool skipStoredProcedures) =>
extractModelCommand.Options.Add(projectPathOption); // Updated from AddOption for beta5 compatibility
extractModelCommand.Options.Add(skipTablesOption);
extractModelCommand.Options.Add(skipViewsOption);
extractModelCommand.Options.Add(skipStoredProceduresOption);

extractModelCommand.SetAction(async (ParseResult parseResult) => // Updated from SetHandler for beta5 compatibility
{
var projectPath = parseResult.GetValue(projectPathOption);
var skipTables = parseResult.GetValue(skipTablesOption);
var skipViews = parseResult.GetValue(skipViewsOption);
var skipStoredProcedures = parseResult.GetValue(skipStoredProceduresOption);

var handler = host.Services.GetRequiredService<ExtractModelCommandHandler>();
var options = new ExtractModelCommandHandlerOptions(projectPath, skipTables, skipViews, skipStoredProcedures);
await handler.HandleAsync(options);
}, projectPathOption, skipTablesOption, skipViewsOption, skipStoredProceduresOption);
});

return extractModelCommand;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
namespace GenAIDBExplorer.Console.CommandHandlers;

/// <summary>
/// Defines the contract for a command handler.
/// Defines the contract for a command handler using System.CommandLine 2.0.0-beta5 patterns.
/// </summary>
/// <remarks>
/// Implementations of this interface are responsible for handling commands with specified options.
/// With System.CommandLine beta5, handlers use ParseResult parameters instead of individual typed parameters.
/// </remarks>
public interface ICommandHandler<TOptions> where TOptions : ICommandHandlerOptions
{
Expand Down
Loading