Skip to content

Conversation

@walterlv
Copy link
Member

@walterlv walterlv commented Sep 8, 2025

No description provided.

Copy link

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 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.

@walterlv walterlv requested a review from SeWZC September 9, 2025 02:07
SeWZC
SeWZC previously approved these changes Sep 9, 2025
@lindexi lindexi merged commit 67d4af0 into main Sep 18, 2025
3 checks passed
@lindexi lindexi deleted the t/lvyi/sub-command branch September 18, 2025 09:48
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.

3 participants