-
Notifications
You must be signed in to change notification settings - Fork 3
Support subcommand #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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 implements comprehensive support for subcommands (multi-level commands) in the command line parser library. The primary purpose is to allow commands like git remote add, docker container run, or kubectl cluster node delete to be properly parsed and handled.
Key changes include:
- Renamed VerbAttribute to CommandAttribute to better reflect the modern concept of main commands and subcommands
- Updated parsers to handle multi-level command names separated by spaces
- Enhanced command matching to support the longest possible command path
Reviewed Changes
Copilot reviewed 49 out of 51 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/DotNetCampus.CommandLine/Compiler/VerbAttribute.cs |
Renames VerbAttribute to CommandAttribute with space-separated command support |
src/DotNetCampus.CommandLine/Utils/Parsers/*.cs |
Updates all parsers to handle multi-level commands instead of single verbs |
tests/DotNetCampus.CommandLine.Tests/SubcommandTests.cs |
Adds comprehensive test suite for subcommand functionality |
| Various analyzer and generator files | Updates terminology and logic from "verb" to "command" throughout |
Files not reviewed (2)
- samples/DotNetCampus.CommandLine.Sample/Properties/LocalizableStrings.Designer.cs: Language not supported
- src/DotNetCampus.CommandLine.Analyzer/Properties/Localizations.Designer.cs: Language not supported
Comments suppressed due to low confidence (2)
tests/DotNetCampus.CommandLine.Tests/PowerShellCommandLineParserTests.cs:1
- Assert.AreEqual on line 342 should use CollectionAssert.AreEqual for array comparison to avoid reference equality issues.
using System.Collections.Generic;
tests/DotNetCampus.CommandLine.Tests/FlexibleCommandLineParserTests.cs:694
- Calling Count() on IEnumerable causes enumeration twice (once for Count() and once for ToArray()). Consider using ToArray() first and checking its Length property.
[TestMethod("11.3. 支持分号分隔的列表")]
public void SemicolonSeparatedList_ParsedCorrectly()
{
// Arrange
string[] args = ["--names:John;Jane;Doe"];
IEnumerable<string>? names = null;
// Act
CommandLine.Parse(args, Flexible)
.AddHandler<Flexible16_ListOptions>(o =>
{
names = o.Names;
return 0;
})
.Run();
// Assert
Assert.IsNotNull(names);
Assert.AreEqual(3, names.Count());
CollectionAssert.AreEqual(new[] { "John", "Jane", "Doe" }, names.ToArray());
}
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
No description provided.