commandlineparser / commandlineparser/commandline
Implement --no-SOME_OPTION
- 主要语言
- C#
- 星标
- 4.8k
- 派生
- 478
- PR 合并指标
- 30 天内没有已合并 PR
描述
I want these mutually exclusive options:
- --updateParts
- --not-updateParts
The default is to update parts, and it's disabled if the second flag is passed. The user needs to pass one flag or the other (so they don't get a behavior they didn't explicitly ask for).
Is there any way to do this? I had a go with this:
`class Options
{
private static bool _updateParts;
public Options(bool updateParts, bool doNotUpdateParts)
{
_updateParts = updateParts;
if (doNotUpdateParts) _updateParts = false;
}
[Option('c', "updateParts", SetName = "update", Required = true, Default = true)]
public static bool UpdateParts { get { return _updateParts; } }
[Option('C', "no-updateParts", SetName = "noUpdate", Required = true, Default = false)]
public static bool DoNotUpdateParts { get { return !_updateParts; } }
}`
Generally speaking this works, but it means I can't add two other options which are mutually exclusive. Imagine I now want to add:
- --doLogging
- --not-doLogging
I can't make them mutually exclusive because they don't belong to either set update or noUpdate.
贡献指南
这个仓库没有索引到贡献指南
调研方向
未指定源文件或测试。首先跟踪 Option 属性、SetName、Required 和 Default 的验证方式,然后检查多个互斥组是如何表示的。当独立的 updateParts 和 doLogging 标志对能够分别强制执行各自的互斥性,且组之间不会发生冲突,并覆盖省略标志和冲突标志时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- csharp
- 领域
- cli
- Issue 类型
- 功能
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100