Add pre and post processor support to cli hosting#76
Merged
darthsharp merged 9 commits intomainfrom Feb 1, 2026
Merged
Conversation
…ind` values - Updated `EnableHelp` to accept an array of `HelpCommandKind` for improved flexibility. - Enhanced `HelpHandlerSettings` to handle multiple command kinds. - Introduced new `EmptyArgs` support in `HelpCommandKind`. - Added relevant unit tests to validate the updated help behavior. - Streamlined code by refactoring help printing logic into reusable methods.
- Added `ICliPreProcessor` and `ICliPostProcessor` interfaces with customizable execution conditions. - Implemented `PrintHeaderPreProcessor` to support printing header text/markup during CLI execution. - Enhanced `DefaultCliHost` to incorporate pre- and post-processing logic for commands and help printing. - Updated `CliHostBuilderExtensions` to provide helper methods for registering pre- and post-processors. - Migrated `CliResult` to `CreativeCoders.Cli.Core` namespace for consistency. - Updated unit tests to reflect pre- and post-processor injections in `DefaultCliHost`.
- Renamed `PreProcessorExecutionCondition` to `CliProcessorExecutionCondition` for better alignment with naming conventions. - Added `PrintFooterPostProcessor` for footer rendering as text or markup. - Enhanced `DefaultCliHost` with separated pre- and post-processor execution for help and command handling. - Updated `CliHostBuilderExtensions` with new methods for printing header/footer text and markup. - Adjusted existing pre- and post-processor logic to support the renamed execution condition type.
…behavior with help and command execution
…ly]` and `[ExcludeFromCodeCoverage]` for improved code clarity and coverage analysis.
- Added `[PublicAPI]` attributes to interfaces and classes to enhance IDE support and improve code clarity. - Removed unused property `IsDefaultCommand` from `CliCommandAttribute`. - Fixed a minor parameter name typo in XML documentation.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds support for pre and post processors to the CLI hosting framework, allowing execution of custom logic before and after command execution or help display. It also enhances the help system to support multiple help command kinds, including empty arguments.
Changes:
- Introduced
ICliPreProcessorandICliPostProcessorinterfaces with execution conditions (Always, OnlyOnHelp, OnlyOnCommand) - Enhanced help command configuration to support multiple
HelpCommandKindvalues simultaneously, including a newEmptyArgsoption - Moved
CliResultfromCreativeCoders.Cli.HostingtoCreativeCoders.Cli.Corenamespace for better architectural separation
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| source/Cli/CreativeCoders.Cli.Core/ICliPreProcessor.cs | New interface for pre-processors executed before commands/help |
| source/Cli/CreativeCoders.Cli.Core/ICliPostProcessor.cs | New interface for post-processors executed after commands/help |
| source/Cli/CreativeCoders.Cli.Core/CliProcessorExecutionCondition.cs | New enum defining when processors should execute |
| source/Cli/CreativeCoders.Cli.Core/CliResult.cs | Moved to Core namespace for better separation |
| source/Cli/CreativeCoders.Cli.Hosting/DefaultCliHost.cs | Added processor execution logic with conditional filtering |
| source/Cli/CreativeCoders.Cli.Hosting/DefaultCliHostBuilder.cs | Added processor registration methods |
| source/Cli/CreativeCoders.Cli.Hosting/ICliHostBuilder.cs | Added processor registration to public API |
| source/Cli/CreativeCoders.Cli.Hosting/PreProcessors/PrintHeaderPreProcessor.cs | Built-in processor for printing headers |
| source/Cli/CreativeCoders.Cli.Hosting/PreProcessors/PrintFooterPostProcessor.cs | Built-in processor for printing footers |
| source/Cli/CreativeCoders.Cli.Hosting/CliHostBuilderExtensions.cs | Extension methods for common processor scenarios |
| source/Cli/CreativeCoders.Cli.Hosting/Help/HelpCommandKind.cs | Added EmptyArgs option |
| source/Cli/CreativeCoders.Cli.Hosting/Help/HelpHandlerSettings.cs | Changed to support multiple help kinds |
| source/Cli/CreativeCoders.Cli.Hosting/Help/CliCommandHelpHandler.cs | Updated to handle multiple help command kinds |
| source/Cli/CreativeCoders.Cli.Core/CliCommandAttribute.cs | Removed unused IsDefaultCommand property |
| tests/CreativeCoders.Cli.Tests/Hosting/DefaultCliHostTests.cs | Added comprehensive tests for processor execution |
| tests/CreativeCoders.Cli.Tests/Hosting/DefaultCliHostBuilderTests.cs | Updated for API changes |
| tests/CreativeCoders.Cli.Tests/Hosting/CliCommandHelpHandlerTests.cs | Added tests for multiple help kinds |
| samples/CliHostSampleApp/Program.cs | Demonstrates new processor functionality |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ution in `DefaultCliHost` - Introduced `CliPreProcessorException` and `CliPostProcessorException` for detailed error reporting during pre- and post-processor execution failures. - Added `PreProcessorFailed` and `PostProcessorFailed` exit codes in `CliExitCodes`. - Refactored `DefaultCliHost` to centralize processor execution logic with dedicated methods (`ExecutePreProcessorsAsync` and `ExecutePostProcessorsAsync`). - Created `CliHostSettings` to support additional configuration options like `UseValidation`. - Adjusted exception handling to improve error feedback in CLI execution.
…ors in `DefaultCliHost` - Added tests to ensure exceptions thrown by pre-processors and post-processors are caught, and appropriate exit codes (`PreProcessorFailed`, `PostProcessorFailed`) are set.
…r rendering in `ICliHostBuilder` and extensions - Introduced `RegisterPreProcessor` and `RegisterPostProcessor` methods to `ICliHostBuilder` for better encapsulation of processor logic. - Added `PrintHeaderText`, `PrintHeaderMarkup`, `PrintFooterText`, and `PrintFooterMarkup` extension methods for streamlined header/footer rendering support. - Enhanced usability by supporting optional execution conditions and configuration actions for processors.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.