Skip to content

Add options validation support to cli hosting and some minor changes for running the CliHost#65

Merged
darthsharp merged 4 commits into
mainfrom
feature/cliandprocessenhacements
Dec 23, 2025
Merged

Add options validation support to cli hosting and some minor changes for running the CliHost#65
darthsharp merged 4 commits into
mainfrom
feature/cliandprocessenhacements

Conversation

@darthsharp

Copy link
Copy Markdown
Contributor

No description provided.

- Introduce `UseValidation` in `ICliHostBuilder` and `CliHostSettings` to enable command options validation.
- Add `IOptionsValidation` interface and `OptionsValidationResult` for asynchronous options validation.
- Enhance `DefaultCliHost` with validation logic and custom `CliCommandOptionsInvalidException`.
- Extend `CliExitCodes` with `CommandOptionsInvalid`.
- Add and update unit tests to cover validation scenarios.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for command options validation in the CLI hosting framework and introduces a new RunMainAsync method for direct integer exit code return. The implementation allows commands to implement IOptionsValidation interface for custom validation logic with automatic validation execution when enabled.

Key changes:

  • Added options validation support via IOptionsValidation interface and OptionsValidationResult class
  • Introduced UseValidation() method on ICliHostBuilder to enable/disable validation
  • Added RunMainAsync() convenience method to ICliHost for returning exit codes directly as integers

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
source/Cli/CreativeCoders.Cli.Core/IOptionsValidation.cs New interface for command options validation
source/Cli/CreativeCoders.Cli.Core/OptionsValidationResult.cs New class to represent validation results with status and messages
source/Cli/CreativeCoders.Cli.Core/CommandResult.cs Added constructors for convenient exit code initialization
source/Cli/CreativeCoders.Cli.Hosting/ICliHost.cs Added RunMainAsync method for direct integer exit code return
source/Cli/CreativeCoders.Cli.Hosting/ICliHostBuilder.cs Added UseValidation method to enable/disable options validation
source/Cli/CreativeCoders.Cli.Hosting/DefaultCliHost.cs Implemented validation logic, RunMainAsync method, and added CliHostSettings class
source/Cli/CreativeCoders.Cli.Hosting/DefaultCliHostBuilder.cs Implemented UseValidation method to configure validation settings
source/Cli/CreativeCoders.Cli.Hosting/Exceptions/CliCommandOptionsInvalidException.cs New exception type for invalid command options
source/Cli/CreativeCoders.Cli.Hosting/CliExitCodes.cs Added CommandOptionsInvalid exit code constant
tests/CreativeCoders.Cli.Tests/Hosting/DefaultCliHostTests.cs Added comprehensive tests for validation scenarios and RunMainAsync
tests/CreativeCoders.Cli.Tests/Hosting/DefaultCliHostBuilderTests.cs Added tests for UseValidation configuration

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/CreativeCoders.Cli.Tests/Hosting/DefaultCliHostTests.cs Outdated
Comment thread source/Cli/CreativeCoders.Cli.Core/CommandResult.cs Outdated
Comment thread source/Cli/CreativeCoders.Cli.Hosting/DefaultCliHost.cs
Comment thread tests/CreativeCoders.Cli.Tests/Hosting/DefaultCliHostTests.cs
Comment on lines +330 to +331
settings?.UseValidation
.Should().NotBe(true);

Copilot AI Dec 23, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assertion "Should().NotBe(true)" is an indirect way of checking that validation is disabled. This could pass if settings is null or if UseValidation is false. Consider being more explicit: check if settings is null OR if it exists, verify that UseValidation is explicitly false. This would make the test intent clearer and distinguish between "settings not added" versus "settings added with validation disabled".

Suggested change
settings?.UseValidation
.Should().NotBe(true);
if (settings == null)
{
settings.Should().BeNull();
}
else
{
settings.UseValidation.Should().BeFalse();
}

Copilot uses AI. Check for mistakes.
darthsharp and others added 3 commits December 23, 2025 18:01
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ionsInvalidException.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@darthsharp darthsharp merged commit 04e2770 into main Dec 23, 2025
6 checks passed
@darthsharp darthsharp deleted the feature/cliandprocessenhacements branch December 23, 2025 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants