Skip to content

Add pre and post processor support to cli hosting#76

Merged
darthsharp merged 9 commits intomainfrom
feature/preandpostprocessors
Feb 1, 2026
Merged

Add pre and post processor support to cli hosting#76
darthsharp merged 9 commits intomainfrom
feature/preandpostprocessors

Conversation

@darthsharp
Copy link
Copy Markdown
Contributor

No description provided.

…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.
…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.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 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 ICliPreProcessor and ICliPostProcessor interfaces with execution conditions (Always, OnlyOnHelp, OnlyOnCommand)
  • Enhanced help command configuration to support multiple HelpCommandKind values simultaneously, including a new EmptyArgs option
  • Moved CliResult from CreativeCoders.Cli.Hosting to CreativeCoders.Cli.Core namespace 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.

Comment thread samples/CliHostSampleApp/Program.cs
Comment thread source/Cli/CreativeCoders.Cli.Hosting/DefaultCliHost.cs Outdated
Comment thread source/Cli/CreativeCoders.Cli.Hosting/DefaultCliHost.cs Outdated
Comment thread source/Cli/CreativeCoders.Cli.Hosting/DefaultCliHost.cs Outdated
Comment thread source/Cli/CreativeCoders.Cli.Hosting/ICliHostBuilder.cs
…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.
@darthsharp darthsharp merged commit c24052d into main Feb 1, 2026
6 checks passed
@darthsharp darthsharp deleted the feature/preandpostprocessors branch February 1, 2026 13:34
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