Repository navigation
CLI framework for easy creation of CLI apps with commands and help support - #64
Merged
Merged
Conversation
…on, introduce new tree-based structure, and update attribute for alternative commands.
- Replace `CliCommandStore` implementation with an optimized tree-based structure. - Introduce `ICliCommandStore` interface, update `DefaultCliHost` and related builders for extensibility. - Enhance command scanning and retrieval functionality to improve flexibility and usability. - Add unit tests for `CliCommandStore` and related functionality. - Update service registration in `AddCliHosting` for seamless integration. - Include support for alternative command paths in `CliCommandAttribute`.
- Refactor `CliTreeNode`, `CliCommandNode`, and `CliCommandGroupNode` to include parent nodes. - Replace command retrieval methods with `FindCommandNodeResult` to track remaining arguments. - Update `DefaultCliHost` and `CliCommandStore` to align with new structure. - Introduce unit tests for enhanced group and command node retrieval.
- Update `ICliCommand` to use `in` variance for generic type. - Add `DemoCliCommandWithOptions` and `DemoOptions` to demonstrate commands with options. - Refactor `DefaultCliHost` for separation of command creation and execution logic. - Introduce `ImplementsGenericInterface` in `TypeExtensions`.
- Introduced `CliCommandNotFoundException` for missing commands. - Added `CliCommandConstructionFailedException` for command creation failures. - Updated `DefaultCliHost` to utilize the new exceptions.
…c exit scenarios: - Update `CliCommandNotFoundException` and `CliCommandConstructionFailedException` to extend `CliExitException`. - Add `CliExitCodes` for standardized exit code definitions. - Refactor `DefaultCliHost` to leverage the new exception hierarchy for improved error handling.
- Add `CommandInfoCreator` and `ICommandInfoCreator` for handling `CliCommandInfo` instantiation. - Update `AssemblyCommandScanner` to leverage `ICommandInfoCreator` for improved modularity and clarity. - Extend `CliCommandInfo` with an `OptionsType` property for enhanced command metadata. - Add `CommandInfoCreator` service registration in `AddCliHosting`. - Refactor `DefaultCliHostBuilder` and `DefaultCliHost` to integrate the new command info creation flow.
…consistency and modularity in command info creation
…ved test isolation and command creation behavior validation.
…and creation and execution: - Extend `CommandInfoCreator` to support `OptionsType` identification for commands. - Update `DefaultCliHost` to leverage `CommandInfoCreator` for command metadata handling. - Simplify `ExecuteAsync` logic by using `OptionsType` directly from `CliCommandInfo`.
- Introduce comprehensive test coverage for `CommandInfoCreator` to validate command info creation behavior. - Test cases include scenarios with valid commands, generic commands, attributed types, and error handling for invalid commands.
…suggestions: - Add `IAnsiConsole` for formatting error outputs in `DefaultCliHost`. - Enhance error handling for command creation and missing commands with detailed user feedback. - Register `IAnsiConsole` in `AddCliHosting` and update dependencies. - Update project with `Spectre.Console` package reference.
- Introduce `ICliCommandHelpHandler` and its implementations (`CliCommandHelpHandler`, `DisabledCommandHelpHandler`) for managing help command behavior. - Add `HelpHandlerSettings` and `HelpCommandKind` to enable configurable help patterns (command, argument, or both). - Update `DefaultCliHost` to invoke help handling logic before command execution. - Extend `ICliHostBuilder` and `DefaultCliHostBuilder` with `EnableHelp` for enabling and configuring help support.
…ality: - Update `CliCommandAttribute` to support properties for `Name` and `Description` with null-check validation for commands. - Overhaul `CliCommandHelpHandler` for detailed help generation, including command syntax, options, and arguments. - Enable help handling in `CliHostSampleApp` and add option description capabilities. - Add dependency on `CreativeCoders.Core` for validation utilities. - Simplify and expand help-related logic in `OptionsHelpGenerator`. - Refactor `AddCliHosting` and register `IOptionsHelpGenerator`. - Fix minor issues and update references in affected projects and test cases.
…erty and update related logic: - Replace jagged array with single-dimensional array in `AlternativeCommands`. - Adjust `CliCommandStore` to handle new property structure. - Update samples and tests to align with the updated `AlternativeCommands` implementation.
… help customization: - Add `CliCommandGroupAttribute` for grouping and providing descriptions for commands. - Rename `Scan` to `ScanForCommands` in `IAssemblyCommandScanner` and related implementations for clarity. - Enhance `CliCommandHelpHandler` to utilize additional table columns for improved formatting. - Add `SkipScanEntryAssembly` method to `ICliHostBuilder` and refactor entry assembly scanning for configurability. - Update tests (`AssemblyCommandScannerTests`) to reflect changes in command scanning method.
- Add `PrintHelpFor` method to `ICliCommandHelpHandler` and its implementations. - Refactor `CliCommandStore` to ensure robust group node creation. - Update `DefaultCliHost` to use `PrintHelpFor` for better command suggestion display. - Adjust `CliCommandHelpHandler` for public accessibility of `PrintHelpFor`.
- Introduce `CliCommandGroupAttribute` for defining and grouping commands with descriptions. - Update `IAssemblyCommandScanner` to return `AssemblyScanResult` with command and group metadata. - Extend `CliCommandStore` to handle command groups, including attribute-based assignment. - Add `GetNamePath` method to `CliTreeNode` for hierarchical path construction. - Refactor tests, samples, and implementations to align with the updated structure.
…s commands: - Introduce `CommandStructureValidator` and its interface for validating CLI command structures. - Add exceptions (`CliCommandStructureValidationException`, `CliCommandGroupDuplicateException`, `AmbiguousCliCommandsException`) for detailed error handling. - Extend `CliCommandStore` and `ICliCommandStore` to expose `GroupAttributes` for validation purposes.
…o CLI host-building process. Fix minor comment typo.
… update related references, and add targeted tests for validation edge cases.
…ScannerTests`: - Verify that group attributes are correctly identified during assembly scanning. - Introduce dynamic assembly generation to test group attribute behavior.
…group help formatting in `CliCommandHelpHandler`.
…mands list: - Correct logic to return early when no commands are available. - Ensure proper display flow for command lists in help output.
…struction: - Verify support for multiple root commands. - Test nested group command setups with full hierarchy validation. - Validate alternative commands and alias handling in tree structure.
…mmandStore`: - Verify correct assignment of group attributes to tree nodes. - Ensure attributes are not assigned when paths do not match.
- Ensure proper registration and behavior of CLI host services (`HelpHandler`, `CommandValidator`, etc.). - Test help handling, command execution, and error scenarios in `DefaultCliHost`.
- Simplify property and constructor definitions using concise syntax. - Apply `UsedImplicitly` attribute improvements for clarity.
…gic: - Introduce `CliHostingIntegrationTests` covering help requests, successful and failing commands, option parsing, and error scenarios. - Extend `IAssemblyCommandScanner` to support filtering commands with an optional predicate. - Update `DefaultCliHostBuilder` service registration order. - Improve `CliCommandHelpHandler` logic to handle command list display properly. - Add `ExcludeFromCodeCoverage` to `DisabledCommandHelpHandler`.
…andler`: - Specify English as the required language for comments, documentation, and code. - Fix minor grammar issue in test guideline section. - Remove unused `CreativeCoders.Core.Collections` import.
- Cover `ShouldPrintHelp` logic for help handling via commands and arguments. - Test `PrintHelp` for commands with descriptions, syntax, options, and groups. - Ensure proper initialization of `CliCommandHelpHandler` and dependencies. - Simplify null checks in `SetupLocalization`.
… and immutability: - Use `init` for immutable properties in `HelpHandlerSettings`, `CommandResult`, `CliCommandAttribute`, and others. - Mark relevant classes with `[PublicAPI]` for improved annotation support. - Make `FindCommandGroupNode` static in `CliCommandStore`. - Replace `List` with array initializer syntax where possible. - Remove redundant methods in `CliCommandGroupNode`. - Adjust exception constructors for cleaner formatting.
- Introduce `ICliCommandContext` with `AllArgs` and `OptionsArgs` properties. - Ensure `DefaultCliHost` initializes and populates the context with arguments. - Update `UseContext` in `DefaultCliHostBuilder` for service registration and configuration. - Add unit tests for command context and argument handling.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements a comprehensive CLI framework for creating command-line applications with support for commands, sub-commands, command groups, help functionality, and options parsing. The implementation includes a hierarchical command structure using tree nodes, dependency injection through a host builder pattern, and comprehensive testing.
Key Changes:
- Implements a CLI hosting framework with command discovery, validation, and execution
- Adds help system supporting multiple modes (command, argument, or both)
- Creates a tree-based command storage system for hierarchical command structures
- Provides comprehensive test coverage with unit and integration tests
Reviewed changes
Copilot reviewed 55 out of 55 changed files in this pull request and generated 15 comments.
Show a summary per file
| File | Description |
|---|---|
source/Cli/CreativeCoders.Cli.Core/* |
Core interfaces and attributes for CLI commands, contexts, and command groups |
source/Cli/CreativeCoders.Cli.Hosting/Commands/* |
Command scanning, storage, validation, and metadata creation |
source/Cli/CreativeCoders.Cli.Hosting/Help/* |
Help handler implementations for displaying command documentation |
source/Cli/CreativeCoders.Cli.Hosting/Exceptions/* |
Custom exceptions for CLI error handling |
source/Cli/CreativeCoders.Cli.Hosting/DefaultCliHost*.cs |
Main host and builder implementations for CLI execution |
tests/CreativeCoders.Cli.Tests/Hosting/* |
Comprehensive unit and integration tests for all CLI components |
samples/CliHostSampleApp/* |
Sample application demonstrating CLI framework usage |
.junie/guidelines.md, .github/csharp.instructions.md |
Updated development guidelines for testing and formatting |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Add `DisposeAsync` calls in `CliHostingIntegrationTests` to release resources after assertions. - Refactor `DemoCliCommand` to simplify structure and ensure consistent return type. - Introduce `DemoCliCommandWithOptions` and extracted `DemoOptions` class for better command organization. - Update `CliExitCodes` with a new constant `CommandResultUnknown` for unhandled cases. - Fix null checks and cleanup logic in `FindCommandNodeResult` and `CliCommandHelpHandlerTests`.
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.