Skip to content

允许在命令行类型中填充原始参数 + 仅 Windows 下才支持斜杠命令行选项#56

Merged
lindexi merged 8 commits intomainfrom
t/lvyi/raw-arguments
Aug 28, 2025
Merged

允许在命令行类型中填充原始参数 + 仅 Windows 下才支持斜杠命令行选项#56
lindexi merged 8 commits intomainfrom
t/lvyi/raw-arguments

Conversation

@walterlv
Copy link
Member

生成的类型预览:

#nullable enable
namespace DotNetCampus.Cli;

/// <summary>
/// 辅助 <see cref="global::DotNetCampus.Cli.DefaultOptions"/> 生成命令行选项、谓词或处理函数的创建。
/// </summary>
internal sealed class DefaultOptionsBuilder
{
    public static object CreateInstance(global::DotNetCampus.Cli.CommandLine commandLine)
    {
        var caseSensitive = commandLine.DefaultCaseSensitive;
        var result = new global::DotNetCampus.Cli.DefaultOptions
        {
            // 1. [RawArguments]
            MainArgs = (string[])commandLine.CommandLineArguments,

            // 2. [Option]
            // There is no option to be initialized.

            // 3. [Value]
            // There is no positional argument to be initialized.
        };

        // 1. [RawArguments]
        // result.MainArgs = commandLine.CommandLineArguments;

        // 2. [Option]
        if (commandLine.GetOption("default-text") is { } o0)
        {
            result.DefaultText = o0;
        }
        if (commandLine.GetOption("default-directory") is { } o1)
        {
            result.DefaultDirectory = o1;
        }

        // 3. [Value]
        // There is no positional argument to be assigned.

        return result;
    }
}

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 introduces support for [RawArguments] attribute to allow command line types to capture the original raw arguments. The implementation adds a new attribute that can be applied to string[] or IReadOnlyList<string> properties to receive the complete set of command line arguments.

Key changes:

  • Added RawArgumentsAttribute for marking properties that should receive raw command line arguments
  • Extended the code generator to handle raw arguments properties alongside existing option and value properties
  • Refactored property collection logic to use a common helper method for better maintainability

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
RawArgumentsAttribute.cs Defines the new attribute for marking raw arguments properties
CommandModelProvider.cs Updates the model provider to detect and handle raw arguments properties, includes refactoring of property collection logic
BuilderGenerator.cs Extends the code generator to emit initialization code for raw arguments properties
DefaultOptions.cs Sample usage showing the new attribute applied to a MainArgs property

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@walterlv walterlv changed the title 允许在命令行类型中填充原始参数 允许在命令行类型中填充原始参数 + 仅 Windows 下才支持斜杠命令行选项 Aug 28, 2025
@lindexi lindexi merged commit 137eee9 into main Aug 28, 2025
3 checks passed
@lindexi lindexi deleted the t/lvyi/raw-arguments branch August 28, 2025 01:00
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