commandlineparser / commandlineparser/commandline
Support for implicit empty string
- 主要语言
- C#
- 星标
- 4.8k
- 派生
- 478
- PR 合并指标
- 30 天内没有已合并 PR
描述
I want to design an api with a bool-like option which can optionally contains a name. Below are my commands I wanted to work with:
``` shell
// 1. Call MyFeature without adding a project
myfeature
// 2. Call MyFeature and add a project with default naming
myfeature --add-project
// 3. Call MyFeature and add a project with a specific name
myfeature --add-project "myprojectname"
```
Below is my options class:
``` csharp
[Verb("myfeature")]
public class MyOptions
{
[Option("add-project", Required = false)]
public string AddProjectName { get; set; }
public bool AddProject => AddProjectName != null;
}
```
My problem is that the 2. solution is not working, because the engine forces the user to set a string arg. In order to set an empty string he has to be give an empty "". But that would not be an intuitive api.
Is there already a solution for this design problem? Can I disable the string-check for this item? I already set "Required" to false.
贡献指南
这个仓库没有索引到贡献指南
调研方向
该 issue 没有指定源文件、测试或入口点。首先跟踪字符串值选项的解析方式,以及缺少值时的拒绝方式。当 --add-project 可以在不带值的情况下工作,同时 --add-project "myprojectname" 仍保留所提供的名称时,即可视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- csharp
- 领域
- cli
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 30/100