-
Notifications
You must be signed in to change notification settings - Fork 3
重构命令行解析库:采用源生成器技术,全面支持五种命令行风格,并增强类型系统 #42
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
Merged
Merged
Conversation
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
原来的代码在当时的条件下过于追求性能,用了很多取巧的方法,不好改写成新时代的源生成器,也不容易支持 required init
lindexi
reviewed
Apr 12, 2025
lindexi
reviewed
Apr 12, 2025
src/dotnetCampus.CommandLine.Analyzer/Generators/ModelProviding/CommandModelProvider.cs
Outdated
Show resolved
Hide resolved
lindexi
reviewed
Apr 12, 2025
src/dotnetCampus.CommandLine.Analyzer/Generators/ModelProviding/CommandModelProvider.cs
Outdated
Show resolved
Hide resolved
lindexi
reviewed
Apr 12, 2025
src/dotnetCampus.CommandLine.Analyzer/Properties/Localizations.zh-hans-cn.resx
Outdated
Show resolved
Hide resolved
lindexi
reviewed
Apr 12, 2025
src/dotnetCampus.CommandLine.Analyzer/Properties/Localizations.zh-hans-cn.resx
Outdated
Show resolved
Hide resolved
lindexi
reviewed
Apr 12, 2025
src/dotnetCampus.CommandLine.Analyzer/Properties/Localizations.zh-hans-cn.resx
Outdated
Show resolved
Hide resolved
lindexi
reviewed
Apr 12, 2025
src/dotnetCampus.CommandLine.Analyzer/Utils/CodeAnalysis/AttributeExtensions.cs
Outdated
Show resolved
Hide resolved
lindexi
reviewed
Apr 12, 2025
src/dotnetCampus.CommandLine.Analyzer/Utils/CodeAnalysis/TypeSymbolExtensions.cs
Outdated
Show resolved
Hide resolved
lindexi
reviewed
Apr 12, 2025
src/dotnetCampus.CommandLine/Exceptions/CommandLineParseException.cs
Outdated
Show resolved
Hide resolved
lindexi
reviewed
Apr 12, 2025
src/dotnetCampus.CommandLine/Utils/CommandLineValueConverter.cs
Outdated
Show resolved
Hide resolved
lindexi
reviewed
Apr 12, 2025
src/dotnetCampus.CommandLine/Utils/Handlers/DictionaryCommandHandlerCollection.cs
Outdated
Show resolved
Hide resolved
lindexi
reviewed
Apr 12, 2025
src/dotnetCampus.CommandLine/Utils/Handlers/TaskCommandHandler.cs
Outdated
Show resolved
Hide resolved
lindexi
reviewed
Apr 12, 2025
lindexi
reviewed
Apr 14, 2025
lindexi
reviewed
Apr 14, 2025
lindexi
reviewed
Apr 14, 2025
tests/DotNetCampus.CommandLine.Performance/DotNetCampus.CommandLine.Performance.csproj
Outdated
Show resolved
Hide resolved
lindexi
approved these changes
Apr 14, 2025
This was referenced Apr 14, 2025
Closed
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.
重大更新
3.x -> 4.0
dotnetCampus.CommandLine 4.0版本带来了全面的架构升级和功能增强,使命令行参数解析更加高效、灵活且易于使用。
主要更新内容
1. 全面采用源代码生成器
XxxParser
)和反射解析器(RuntimeParser
)2. 全面增强的命令行风格支持
CommandLineStyle.Flexible
(默认):智能识别多种风格CommandLineStyle.GNU
:符合 GNU 规范的风格CommandLineStyle.POSIX
:符合 POSIX 规范的风格CommandLineStyle.DotNet
:.NET CLI 风格CommandLineStyle.PowerShell
:PowerShell 风格--option value
、--option=value
、--option:value
-o value
、-o=value
、-o:value
/option value
、/option:value
--flag
(无值时自动设为true)、--flag:true/false
protocol://command/subcommand?param1=value¶m2=value
3. 增强的类型系统支持
init
和 C# 11.0 的required
关键字,支持不可变对象4. 改进的命令处理器模式
AddHandler<T>
现在支持实现ICommandHandler
接口的类型,可以在类型内部编写处理逻辑破坏性变更和升级指南
命名空间变更:
OptionAttribute
、ValueAttribute
、VerbAttribute
的命名空间发生了变化。升级库后,您可能需要借助IDE来修正相关引用。参数解析选项变更:
CommandLine.Parse(args, xxx)
的第二个参数已从简单的URL scheme字符串升级为完整的CommandLineParsingOptions
对象:PascalCase
改为推荐使用kebab-case
:原因请见:DCL101.md
标准处理器移除:删除了
AddStandardHandlers
方法(用于自动处理--help
和--version
)。这个功能在未来版本可能会以新形式回归,如有需要请暂时自行实现。过滤器机制移除:删除了很少使用的
CommandLineFilter
机制,该机制主要为AddStandardHandlers
提供支持。保留的功能
本次升级范围很大,不过仍然尽量在更规范更强大的设计中保持了跟上个版本 API 的一致性。你原来的项目通常只进行命名空间的修改即可正常工作;调整选项的命名规则后可消除新引入的警告(我们提供了代码修改器辅助你自动采用新的命名规则)。
git commit
、git push
等形式)