feat(skills): Add system-commandline-cli skill for managing .NET CLI commands based on System.CommandLine library - #2584
Open
massimobonanni wants to merge 1 commit into
Conversation
Contributor
🔒 PR Risk Scan ResultsScanned 1 changed file(s).
✅ No matching risk patterns were detected in changed files.
|
Contributor
🔍 Vally Lint Results✅ All checks passed
Summary
Full linter output |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a reusable skill for developing .NET CLIs with System.CommandLine.
Changes:
- Adds command architecture, handlers, DI, validation, and naming guidance.
- Adds the skill to generated documentation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
skills/system-commandline-cli/SKILL.md |
Defines the new skill and examples. |
docs/README.skills.md |
Lists installation and usage details. |
Suppressed comments (1)
skills/system-commandline-cli/SKILL.md:313
- The checklist reintroduces the unconditional async requirement even if Rule 3 is corrected. Allow a synchronous handler signature when the command performs no asynchronous work.
5. ✅ Handler signature: `async Task<int> CommandHandler(ParseResult, CancellationToken)`
| @@ -0,0 +1,317 @@ | |||
| --- | |||
| name: system-commandline-cli | |||
| description: "Use this skill when adding, modifying, or reviewing CLI commands in a .NET project built with System.CommandLine. Triggers include: creating a new CLI command, adding options or arguments, wiring command handlers, registering subcommands, building command groups, or any architecture decision about CLI command structure. Also use when the user mentions 'System.CommandLine', 'CommandBase', 'SetAction', 'ParseResult', 'RootCommand', 'subcommand', or asks to add a verb to the CLI. Do NOT use for general C# coding, web APIs, UI work, or non-CLI projects." | |||
| # System.CommandLine CLI Developer Skill | ||
|
|
||
| You are working on a .NET CLI application built with **System.CommandLine v2.x.x**, targeting **.NET 8 or later** or any **.NET Standard 2.0** implementation, including **.NET Framework 4.6.1 or later** and **.NET Core 2.0 or later**. | ||
| Follow these rules and patterns strictly when creating or modifying CLI commands. |
|
|
||
| ## RULE 3 — Command Handler Pattern | ||
|
|
||
| Handlers are **async methods** wired via `SetAction`: |
Comment on lines
+197
to
+202
| Add a convenience extension in `ServiceProviderExtensions.cs`: | ||
|
|
||
| ```csharp | ||
| public static IMyService GetMyService(this ServiceProvider provider) | ||
| => provider.GetRequiredService<IMyService>(); | ||
| ``` |
| 1. Set `Recursive = true` so the option is accepted for every descendant command. | ||
| 2. Add each global option exactly once to `RootCommand.Options`; do not duplicate it on leaf commands. | ||
| 3. Read values through the shared symbol, for example | ||
| `parseResult.GetValue(GlobalOptions.Endpoint)`, preferably behind a `CommandBase` helper. |
Comment on lines
+294
to
+295
| 5. Validate endpoint options as nonblank absolute `http` or `https` URIs. Reject unsupported schemes, | ||
| relative URIs, query strings, and fragments because appending a fixed endpoint path would change their meaning. |
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.
Pull Request Checklist
npm startand verified thatREADME.mdis up to date.mainbranch for this pull request.Description
This pull request adds a new skill for working with .NET CLI applications built using System.CommandLine, and documents its usage and conventions. The most important changes are:
New Skill Addition:
system-commandline-cliskill, which provides detailed rules, patterns, and best practices for adding, modifying, or reviewing CLI commands in .NET projects using System.CommandLine. The skill includes when to trigger, what scenarios are in scope, and when not to use it. [1] [2]Documentation Updates:
docs/README.skills.mdto include the newsystem-commandline-cliskill, its installation command, and a clear description of its intended use cases and exclusions.Skill Guidelines and Best Practices:
skills/system-commandline-cli/SKILL.mdwith comprehensive guidelines covering project architecture, command base class usage, options/arguments definition, handler patterns, command grouping, registration, destructive operation confirmation, dependency injection, naming conventions, global options, validation, and a checklist for new commands.Type of Contribution
By submitting this pull request, I confirm that my contribution abides by the Code of Conduct and will be licensed under the MIT License.