Skip to content
Merged
Show file tree
Hide file tree
Changes from 192 commits
Commits
Show all changes
193 commits
Select commit Hold shift + click to select a range
9bad3e9
计划使用新的源生成器解析命令行,从两步生成升级成一步生成
walterlv Sep 12, 2025
3cf6606
开始着手编写尽可能减少分配的命令行解析所需的结构
walterlv Sep 13, 2025
654b937
压缩一下空间
walterlv Sep 13, 2025
958f40c
编写更多的解析代码
walterlv Sep 14, 2025
d90b88a
终于把通用命令行解析器写完了
walterlv Sep 14, 2025
1623465
尝试消除每个属性赋值时的装箱和委托创建
walterlv Sep 15, 2025
418fba5
能赋值字典
walterlv Sep 15, 2025
2dc1c1e
完善解析器的一些分支
walterlv Sep 15, 2025
2c4452a
由于我们有了 handler 来赋值,所以不再需要 optionName 变量
walterlv Sep 15, 2025
c35ebe1
处理不支持多字符短选项的情况
walterlv Sep 15, 2025
29b2e3f
解析时支持集合
walterlv Sep 15, 2025
f61a368
给源生成器编写用来做属性赋值的结构
walterlv Sep 15, 2025
fdcd0cc
试一下初版源生成器(手写版)
walterlv Sep 15, 2025
aa29eb0
支持无子命令的命令行对象也能标记 CommandAttribute
walterlv Sep 15, 2025
9412fbf
初步实现新的解析器的源生成器
walterlv Sep 15, 2025
5edb306
生成选项和位置参数匹配
walterlv Sep 15, 2025
420b19f
生成更多的模型代码
walterlv Sep 15, 2025
e9dcb12
生成枚举解析赋值
walterlv Sep 15, 2025
e845c15
属性去重
walterlv Sep 15, 2025
89cf0e3
源生成器兼容以前的单元测试
walterlv Sep 15, 2025
43092c9
消除警告
walterlv Sep 15, 2025
3f9aad2
删除辅助源生成器编写用的类
walterlv Sep 15, 2025
9994608
整理源生成器涉及到的各种类型
walterlv Sep 16, 2025
2d4dd5e
修正命令的匹配
walterlv Sep 16, 2025
42350ac
修复解析器的一些低级错误
walterlv Sep 16, 2025
c69a26a
使用 nameof,这样能知道是属性名,而不是某个命名法
walterlv Sep 16, 2025
0894492
传递并正确处理异常
walterlv Sep 16, 2025
ac77919
重新梳理默认值逻辑
walterlv Sep 16, 2025
839b7d2
修复前缀判断错误
walterlv Sep 16, 2025
638cca2
单独处理选项中的空格分隔符
walterlv Sep 16, 2025
406f7ca
解析异常抛出正确的异常类型
walterlv Sep 16, 2025
17b2b1b
DotNet 风格中不再适用的单元测试,忽略掉
walterlv Sep 16, 2025
bb3ea99
处理选项只能跟一个值的情况
walterlv Sep 16, 2025
bcb3811
梳理多字符组合的短选项的解析
walterlv Sep 16, 2025
c8c3ecc
修复 PowerShell 风格前缀匹配
walterlv Sep 16, 2025
ac6ee9c
修复剩余所有炸掉的单元测试
walterlv Sep 16, 2025
41fc0f2
避免访问到 CommandLine 中的属性
walterlv Sep 16, 2025
04d4eef
支持 URL 的解析
walterlv Sep 16, 2025
a7fbd93
整理 Benchmark 代码
walterlv Sep 16, 2025
8a535e3
优化解析性能
walterlv Sep 16, 2025
ae6c22d
整理 Benchmark 的类
walterlv Sep 16, 2025
1abc6b9
加入 ConsoleAppFramwork 库的测试
walterlv Sep 17, 2025
8d3355e
调整 AOT 兼容相关
walterlv Sep 17, 2025
f1aaaa7
在 AOT 下删除不支持 AOT 的对照组
walterlv Sep 17, 2025
8607f3d
已知问题:https://github.com/dotnet/runtime/issues/119353
walterlv Sep 17, 2025
1219d4a
优化未传参时候的性能(短路解析器)
walterlv Sep 17, 2025
8522e20
向支持全栈解析靠拢
walterlv Sep 17, 2025
c2e594a
源生成器可处理全栈解析
walterlv Sep 17, 2025
c3c630a
逐步开始栈解析
walterlv Sep 17, 2025
20c5940
使用 SourceTextBuilder 生成拦截器代码
walterlv Sep 17, 2025
512efda
支持 BitCast 和 As 根据目标框架自动选择
walterlv Sep 17, 2025
3bc692c
使用更加规范的源代码构建器的方法名
walterlv Sep 17, 2025
954aaab
使用 builder 构建匹配方法
walterlv Sep 18, 2025
f81cbd4
使用控制流链式调用
walterlv Sep 18, 2025
66b1955
可以添加空行
walterlv Sep 18, 2025
22c4b2a
创建对象也用链式调用
walterlv Sep 18, 2025
e014e91
修复命名空间
walterlv Sep 18, 2025
e67c87a
修复枚举类型的判断
walterlv Sep 18, 2025
776e7ac
修复位置参数没有时候的代码生成
walterlv Sep 18, 2025
b7d668e
处理位置参数匹配的情况
walterlv Sep 19, 2025
516d3cc
ToString 时处理 URL
walterlv Sep 19, 2025
2c00ca4
删除旧的 4.0 的两步解析实现
walterlv Sep 19, 2025
e22e027
继续删除旧的 4.0 的两步解析实现
walterlv Sep 19, 2025
684f4f3
继续删除旧的 4.0 的两步解析实现
walterlv Sep 19, 2025
70b2be4
更严格地检查 option 的命名风格
walterlv Sep 19, 2025
30ce004
支持 record command 和数组 long option 的命名法检测
walterlv Sep 19, 2025
88cdfb8
加入 4.0 命令行的测试程序集
walterlv Sep 19, 2025
b7011a5
适配让 Temp40 能跑过
walterlv Sep 19, 2025
41a092d
使用线上版本
walterlv Sep 19, 2025
0449de3
根据 AI 的审查意见修改
walterlv Sep 19, 2025
bff2d0b
修 CI
walterlv Sep 19, 2025
e0e224c
重新编写中文文档,以适配最新的规范
walterlv Sep 19, 2025
0600c57
补上性能数据
walterlv Sep 19, 2025
e95510c
更新 AI 翻译的文档
walterlv Sep 19, 2025
a0861a4
修复构建
walterlv Sep 19, 2025
331912e
再修复构建
walterlv Sep 20, 2025
9675cd4
添加规则文件,用于作为 AI 单元测试的上下文
walterlv Sep 20, 2025
97751fd
添加更详细的规则测试
walterlv Sep 20, 2025
7963d7f
添加更多测试,并同时发现了 GNU 规则中的 bug
walterlv Sep 20, 2025
600ab43
支持对泛型类型报告错误
walterlv Sep 20, 2025
a491885
增加布尔选项的测试
walterlv Sep 20, 2025
7ec45e5
GNU 不支持布尔选项显式带值
walterlv Sep 20, 2025
fcf6a8b
测试布尔直接跟值的情况
walterlv Sep 20, 2025
253a8b8
更加无歧义地解析短组合选项
walterlv Sep 20, 2025
32e48cf
支持多字符短选项
walterlv Sep 20, 2025
cf4541a
对多字符短选项进行更丰富的测试
walterlv Sep 20, 2025
1bb6b95
测试集合
walterlv Sep 20, 2025
41163ec
添加奇怪的集合
walterlv Sep 20, 2025
326f730
测试字典
walterlv Sep 20, 2025
c0897fd
修复报告错误时,--option-name 选项中的 - 被识别成分隔符了
walterlv Sep 20, 2025
f48d657
修复非 kebab-case 命名法也能匹配 kebab-case 的问题
walterlv Sep 20, 2025
4d22b11
添加命名法测试
walterlv Sep 20, 2025
75120a4
大小写测试
walterlv Sep 20, 2025
8cd35f5
测试位置参数
walterlv Sep 20, 2025
2d6b858
PowerShell 不支持后置位置参数
walterlv Sep 20, 2025
e4fd14f
测试更多位置参数
walterlv Sep 20, 2025
7962217
修正 scheme 拼写
walterlv Sep 20, 2025
1e6dacc
根据单元测试详细整理命令行风格区别
walterlv Sep 20, 2025
ec75c4b
AI 将规则更新同步到其他语言
walterlv Sep 20, 2025
cab1bb0
匹配更多位置参数
walterlv Sep 20, 2025
c0f49ec
添加命令子命令匹配
walterlv Sep 20, 2025
1e317ed
Flexible 测试更多的风格
walterlv Sep 21, 2025
e712768
测更多
walterlv Sep 21, 2025
67ca36e
试图测试各种类型的支持
walterlv Sep 21, 2025
2c3de6a
整理分析器和源生成器,使其支持的类型完全统一
walterlv Sep 21, 2025
685b0fd
整理分析器和源生成器
walterlv Sep 21, 2025
2d1b90f
测试所有支持的属性类型
walterlv Sep 21, 2025
b3adf54
增加不同位置的位置参数的测试
walterlv Sep 21, 2025
922bb83
添加 URL 转义测试
walterlv Sep 21, 2025
4cb8674
URL 单元测试已迁移完毕
walterlv Sep 21, 2025
84d4fc7
假装迁移完之前的测试了
walterlv Sep 21, 2025
366b7f8
删除 3.x 时代的测试
walterlv Sep 21, 2025
71f8ede
移动文件
walterlv Sep 21, 2025
e3e0cfe
更改 Throws
walterlv Sep 21, 2025
f98d334
增加默认值测试
walterlv Sep 21, 2025
656d5f0
重新规定并测试属性初值
walterlv Sep 21, 2025
96aa699
删除给 AI 看的文档
walterlv Sep 21, 2025
13fbc7c
查找重复名称并报告编译错误
walterlv Sep 21, 2025
2e614d1
测试 Linux 路径前缀的干扰
walterlv Sep 21, 2025
30e93b2
为后面自定义命令行解析风格做准备
walterlv Sep 21, 2025
221c85a
给源生成器用的类型,换个地方放
walterlv Sep 21, 2025
88959e3
添加简单的异常处理
walterlv Sep 21, 2025
a259009
修单元测试
walterlv Sep 21, 2025
c78e98b
Copilot 代码审查
walterlv Sep 21, 2025
12fd469
这个项目 debug 也要单元测试的,因为 CommandLineStyle 在 release 下是优化版的魔数,要通过 debug 的…
walterlv Sep 21, 2025
a196048
支持 nameof 的命名法检测
walterlv Sep 21, 2025
5647f6e
可以检查选项名不合法
walterlv Sep 22, 2025
2c66eea
消除警告
walterlv Sep 22, 2025
bbc7fc3
修复单元测试显示字符串错误
walterlv Sep 22, 2025
b074e79
测试一些边界情况
walterlv Sep 22, 2025
3906cd6
修正文档
walterlv Sep 22, 2025
4974a86
更新 README.md
walterlv Sep 22, 2025
69018af
Fix CI
walterlv Sep 22, 2025
9970eee
严格和宽松检查不同时进行
walterlv Sep 22, 2025
eef09c8
干掉 [Conditional("FOR_SOURCE_GENERATION_ONLY")] 因为会让 IDE 误以为没有这个 Attri…
walterlv Sep 23, 2025
f283d51
Revert "干掉 [Conditional("FOR_SOURCE_GENERATION_ONLY")] 因为会让 IDE 误以为没有…
walterlv Sep 23, 2025
86ba8a2
依赖于条件 Attribute 的代码,保证在同一程序集生成,不要跨程序集,不然会分析不到。然后添加单元测试
walterlv Sep 23, 2025
7857e1d
格式化
walterlv Sep 23, 2025
0b6dac0
添加注释
walterlv Sep 23, 2025
84f85c0
Flexible 隐藏支持 --PascalCase 选项
walterlv Sep 23, 2025
ded1103
Fix docs
walterlv Sep 23, 2025
a14d3b0
代码审查
walterlv Sep 23, 2025
98722e1
单独把 --Pascal 拿出来测
walterlv Sep 23, 2025
1d7d3bc
合并测试
walterlv Sep 23, 2025
e1871b4
Update benchmark data
walterlv Sep 23, 2025
dc95234
修复单元测试
walterlv Sep 24, 2025
ae89729
优化 Parser 的赋值判断
walterlv Sep 24, 2025
03d5772
避免性能浪费
walterlv Sep 24, 2025
9350b42
提高 URL 转换性能
walterlv Sep 24, 2025
c19cd7f
修复url解析错误
walterlv Sep 25, 2025
d4d05c2
处理未知选项
walterlv Sep 26, 2025
096eaec
即便存在错误的选项,也依然硬着头皮解析完成,最后再报告错误
walterlv Sep 26, 2025
2dac1e4
支持在命令行解析错误的情况下,仍然给未出错的选项赋值
walterlv Sep 26, 2025
1ed7e81
能准确给出未被忽略的错误信息
walterlv Sep 26, 2025
6a4c193
补充更多单元测试
walterlv Sep 26, 2025
577431c
加一个带状态的 AddHandler
walterlv Sep 26, 2025
d8446a8
命令行执行完后返回更详细的信息
walterlv Sep 26, 2025
937aa14
试图做带状态的命令行参数
walterlv Sep 26, 2025
7cc32ce
整理 CommandRunner,使 CommandLine 对象不可变
walterlv Sep 26, 2025
c4dca4e
优化链式调用
walterlv Sep 26, 2025
3913b7c
提取公共类型到外面
walterlv Sep 26, 2025
64ae500
给创建命令行对象增加上下文
walterlv Sep 26, 2025
f17c231
整理文案
walterlv Sep 26, 2025
8324310
简化状态命令执行器名称
walterlv Sep 26, 2025
c434687
可拦截有状态的命令执行器
walterlv Sep 26, 2025
5a99cde
提取注释
walterlv Sep 26, 2025
2dabf3c
让 AddHandler 的重载更齐全
walterlv Sep 26, 2025
40ca227
测试覆盖所有的 AddHandler
walterlv Sep 26, 2025
59cc2d8
测试异步版的 ForState
walterlv Sep 26, 2025
ae40dd1
文档中提示需要 .ToRunner()
walterlv Sep 26, 2025
bcc5229
添加状态
walterlv Sep 26, 2025
e45c1f8
翻译状态
walterlv Sep 26, 2025
a5aea99
新增异常
walterlv Sep 26, 2025
5b552c6
翻译异常
walterlv Sep 26, 2025
07195f5
所有风格默认都不支持空格分隔的集合
walterlv Sep 26, 2025
c2e8f18
更新文档空格分隔集合
walterlv Sep 26, 2025
892deff
修复文档错误
walterlv Sep 26, 2025
8bd5826
为避免歧义,将 PowerShell 风格重命名为 Windows 经典风格。
walterlv Sep 27, 2025
0274d49
不要一刀切,让旧代码有升级余地
walterlv Sep 27, 2025
3033902
更准确写理由
walterlv Sep 27, 2025
b230906
小优化
walterlv Sep 28, 2025
c5997a0
重新支持直接 AddHandler,因为林德熙不喜欢多调用一个 ToRunner
walterlv Sep 28, 2025
1c449bf
整理拦截器的代码
walterlv Sep 28, 2025
73dbbcf
所有方法去掉 ToRunner
walterlv Sep 28, 2025
369bf80
最终还是在 CommandLine 里把 Runner 放进去了。不过两者都支持
walterlv Sep 28, 2025
85a091d
不需要非空
walterlv Sep 28, 2025
f5978d6
抑制不合理的警告
walterlv Sep 28, 2025
78f24d1
避免创建字典的 Keys 的集合
walterlv Sep 28, 2025
82d429c
减少命令行 Run 方法执行时调用堆栈的层级
walterlv Sep 28, 2025
597234d
允许转换命令行结果为退出代码
walterlv Sep 28, 2025
272ed12
fix target framework tips
walterlv Sep 28, 2025
5aa3631
升级库
walterlv Sep 28, 2025
5c00cf7
代码审查
walterlv Sep 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions .github/workflows/dotnet-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: |
3.1.x
6.0.x
8.0.x
9.0.x

- name: Build
run: dotnet build --configuration Release
run: dotnet build -c release

- name: Test
run: dotnet test --configuration Release
- name: Test Debug
run: dotnet test -c debug

- name: Test Release
run: dotnet test -c release

- name: Pack
run: dotnet pack --configuration Release --no-build
run: dotnet pack ./src/DotNetCampus.CommandLine -c release --no-build
7 changes: 3 additions & 4 deletions .github/workflows/nuget-tag-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: |
3.1.x
6.0.x
8.0.x
9.0.x

- name: Install dotnet tool
run: dotnet tool install -g dotnetCampus.TagToVersion
Expand All @@ -29,8 +28,8 @@ jobs:

- name: Build with dotnet
run: |
dotnet build --configuration Release
dotnet pack --configuration Release --no-build
dotnet build -c release
dotnet pack ./src/DotNetCampus.CommandLine -c release --no-build

- name: Install Nuget
uses: nuget/setup-nuget@v1
Expand Down
11 changes: 7 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<Project>
<ItemGroup>
<PackageVersion Include="BenchmarkDotNet" Version="0.15.2" />
<PackageVersion Include="dotnetCampus.LatestCSharpFeatures" Version="13.0.0" />
<PackageVersion Include="BenchmarkDotNet" Version="0.15.4" />
<PackageVersion Include="ConsoleAppFramework" Version="5.6.1" />
<PackageVersion Include="DotNetCampus.CodeAnalysisUtils" Version="0.0.1-alpha.3" />
<PackageVersion Include="DotNetCampus.CommandLine.Temp40" Version="4.0.1-benchmark.1" />
<PackageVersion Include="DotNetCampus.LatestCSharpFeatures" Version="13.0.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.11.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="MSTest.TestAdapter" Version="3.10.3" />
<PackageVersion Include="MSTest.TestFramework" Version="3.10.3" />
<PackageVersion Include="MSTest.TestAdapter" Version="3.10.4" />
<PackageVersion Include="MSTest.TestFramework" Version="3.10.4" />
<PackageVersion Include="MSTestEnhancer" Version="2.2.2" />
<PackageVersion Include="System.Collections.Immutable" Version="8.0.0" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
Expand Down
11 changes: 11 additions & 0 deletions DotNetCampus.CommandLine.sln
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetCampus.CommandLine.Te
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetCampus.CommandLine.Performance", "tests\DotNetCampus.CommandLine.Performance\DotNetCampus.CommandLine.Performance.csproj", "{56B65FC1-CE75-4981-A880-954D891901D6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetCampus.CommandLine.FakeObjects", "tests\DotNetCampus.CommandLine.FakeObjects\DotNetCampus.CommandLine.FakeObjects.csproj", "{413E4F7B-4E26-4D88-B7E9-13A6831A9E42}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -76,6 +78,14 @@ Global
{56B65FC1-CE75-4981-A880-954D891901D6}.Release|Any CPU.Build.0 = Release|Any CPU
{56B65FC1-CE75-4981-A880-954D891901D6}.Release|x86.ActiveCfg = Release|Any CPU
{56B65FC1-CE75-4981-A880-954D891901D6}.Release|x86.Build.0 = Release|Any CPU
{413E4F7B-4E26-4D88-B7E9-13A6831A9E42}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{413E4F7B-4E26-4D88-B7E9-13A6831A9E42}.Debug|Any CPU.Build.0 = Debug|Any CPU
{413E4F7B-4E26-4D88-B7E9-13A6831A9E42}.Debug|x86.ActiveCfg = Debug|Any CPU
{413E4F7B-4E26-4D88-B7E9-13A6831A9E42}.Debug|x86.Build.0 = Debug|Any CPU
{413E4F7B-4E26-4D88-B7E9-13A6831A9E42}.Release|Any CPU.ActiveCfg = Release|Any CPU
{413E4F7B-4E26-4D88-B7E9-13A6831A9E42}.Release|Any CPU.Build.0 = Release|Any CPU
{413E4F7B-4E26-4D88-B7E9-13A6831A9E42}.Release|x86.ActiveCfg = Release|Any CPU
{413E4F7B-4E26-4D88-B7E9-13A6831A9E42}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -84,6 +94,7 @@ Global
{6B8F7500-B161-408D-BFA3-AE77CB8CF4D8} = {F26EAA27-AA79-4B28-890C-D759F1D1A374}
{70991994-BB0C-4D00-9B74-E8736D0AD7C1} = {7DDA8183-3606-4B08-86E3-A4537860448F}
{56B65FC1-CE75-4981-A880-954D891901D6} = {7DDA8183-3606-4B08-86E3-A4537860448F}
{413E4F7B-4E26-4D88-B7E9-13A6831A9E42} = {7DDA8183-3606-4B08-86E3-A4537860448F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {52E30C59-C5C8-4517-811A-667BFA2BFABB}
Expand Down
6 changes: 6 additions & 0 deletions Nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="Benchmark-Local" value="./tests/DotNetCampus.CommandLine.Performance/CompareTo" />
</packageSources>
</configuration>
106 changes: 62 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
[zh-hans]: /docs/zh-hans/README.md
[zh-hant]: /docs/zh-hant/README.md

DotNetCampus.CommandLine is a simple yet high-performance command line parsing library for .NET. Thanks to the power of source code generators, it provides efficient parsing capabilities with a developer-friendly experience.
DotNetCampus.CommandLine is a simple and high-performance command line parsing library for .NET. Benefiting from source generators (and interceptors), it delivers efficient parsing and a friendly development experience across multiple command line styles. All features live under the `DotNetCampus.Cli` namespace.

Parsing a typical command line takes only about 0.8μs (microseconds), making it one of the fastest command line parsers available in .NET.
Benchmarks show parsing a typical command line takes well under a microsecond in many scenarios, placing it among the fastest .NET command line parsers while still pursuing full‑featured syntax support.

## Get Started

Expand All @@ -37,63 +37,81 @@ class Program
Define a class that maps command line arguments:

```csharp
class Options
public class Options
{
[Value(0)]
public required string FilePath { get; init; }
[Option("debug")]
public required bool IsDebugMode { get; init; }

[Option('s', "silence")]
public bool IsSilence { get; init; }
[Option('c', "count")]
public required int TestCount { get; init; }

[Option('m', "mode")]
public string? StartMode { get; init; }
[Option('n', "test-name")]
public string? TestName { get; set; }

[Option("startup-sessions")]
public IReadOnlyList<string> StartupSessions { get; init; } = [];
[Option("test-category")]
public string? TestCategory { get; set; }

[Option('d', "detail-level")]
public DetailLevel DetailLevel { get; set; } = DetailLevel.Medium;

[Value(0, int.MaxValue)]
public IReadOnlyList<string> TestItems { get; init; } = null!;
}

public enum DetailLevel
{
Low,
Medium,
High,
}
```

Then use different command line styles to populate instances of this type:
Then use different command line styles to populate instances of this type (the library supports multiple styles):

### Windows PowerShell Style
| Style | Example |
| --------------- | ------------------------------------------------------------------------------------------ |
| DotNet | `demo.exe 1.txt 2.txt -c:20 --test-name:BenchmarkTest --detail-level=High --debug` |
| Windows Classic | `demo.exe 1.txt 2.txt 3.txt -c 20 -TestName BenchmarkTest -DetailLevel High -Debug` |
| CMD | `demo.exe 1.txt 2.txt 3.txt /c 20 /TestName BenchmarkTest /DetailLevel High /Debug` |
| Gnu | `demo.exe 1.txt 2.txt 3.txt -c 20 --test-name BenchmarkTest --detail-level High --debug` |
| Flexible | `demo.exe 1.txt 2.txt 3.txt --count:20 /TestName BenchmarkTest --detail-level=High -Debug` |

```powershell
> demo.exe "C:\Users\lvyi\Desktop\demo.txt" -s -Mode Edit -StartupSessions A B C
```
## Command Styles and Features

### Windows CMD Style
Multiple command line styles are supported; select one when parsing (Flexible is default). Styles differ in case sensitivity, accepted prefixes, separators, and naming forms. A detailed capability matrix (boolean literals, collection parsing forms, naming conventions, URL form, etc.) is documented in the full English guide under `docs/en/README.md`.

```cmd
> demo.exe "C:\Users\lvyi\Desktop\demo.txt" /s /Mode Edit /StartupSessions A B C
```
Core capabilities:
- Rich option syntax: long & short options; separators `= : space`; multi-value & repeat forms
- Boolean literals: `true/false`, `yes/no`, `on/off`, `1/0`
- Collections & dictionaries: repeat, comma, semicolon forms; key-value dictionaries
- Positional arguments: via `[Value(index)]` (ranges supported with `(index, length)` overload — second parameter is count)
- Property semantics: `required`, `init`, nullable reference/value types unified behavior
- Commands & subcommands: multi-word `[Command]` supported with handler chaining or `ICommandHandler`
- URL protocol parsing: `scheme://command/sub/positional1?...` for integration scenarios
- High performance: source generators + interceptors, minimizing allocations
- AOT compatible: no reflection; even enum name lookups are avoided at runtime

### Linux/GNU Style
For the full feature matrix (including whether a style supports space-separated collections, explicit boolean values, multi-char short option groups, etc.), see the English documentation table.

```bash
$ demo.exe "C:/Users/lvyi/Desktop/demo.txt" -s --mode Edit --startup-sessions A --startup-sessions B --startup-sessions C
```
### Naming

### .NET CLI Style
```
> demo.exe "C:\Users\lvyi\Desktop\demo.txt" -s:true --mode:Edit --startup-sessions:A;B;C
```
Define options using kebab-case in attributes (e.g., `[Option("test-name")]`). The analyzer warns (`DCL101`) if not kebab-case; we still treat what you write as kebab-case so users may invoke with PascalCase/camelCase depending on style.

## Command Styles and Features
### Required Options and Default Values

Modifiers: `required` (must be supplied), `init` (immutable after construction), `?` (nullable). Initial value semantics follow the table in `docs/en/README.md`: required & missing → exception; nullable + init → null; non-nullable collection → empty; non-nullable scalar → default value (value types) or empty string for `string`; otherwise keep initializer.

### Commands and Subcommands

Register handlers with `AddHandler<T>()` or implement `ICommandHandler`. Multi-word `[Command("remote add")]` expresses subcommands. Ambiguity throws `CommandNameAmbiguityException`. Use `RunAsync` if any handler is async.

### URL Protocol

You may express a command invocation as a URL: `dotnet-campus://1.txt/2.txt?count=20&test-name=BenchmarkTest&detail-level=High&debug` enabling shell integration or deep links.

### Performance

The library supports multiple command line styles through `CommandLineStyle` enum:
- Flexible (default): Intelligently recognizes multiple styles
- GNU: GNU standard compliant
- POSIX: POSIX standard compliant
- DotNet: .NET CLI style
- PowerShell: PowerShell style

Advanced features include:
- Support for various data types including collections and dictionaries
- Positional arguments with `ValueAttribute`
- Required properties with C# `required` modifier
- Command handling with command support
- URL protocol parsing
- High performance thanks to source generators
Benchmarks (see docs for detailed tables) show very low latency (hundreds of ns typical) and minimal allocations compared to earlier versions and other libraries, while preserving rich syntax coverage.

## Engage, Contribute and Provide Feedback

Expand All @@ -107,7 +125,7 @@ Click here to file a new issue:

### Contributing Guide

Be kindly.
Be kind.

## License

Expand Down
Loading
Loading