commandlineparser / commandlineparser/commandline

Support for implicit empty string

未關閉
#765 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
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.

貢獻指南

這個儲存庫沒有索引到貢獻指南

研究方向

The issue names no source files, tests, or entry points. Start by tracing how string-valued options are parsed and how missing values are rejected. Done should mean that --add-project works without a value while --add-project "myprojectname" still preserves the supplied name.

由索引模型根據 Issue 內容生成。

評估

技術堆疊
csharp
領域
cli
Issue 類型
功能
難度
5/5
預估耗時
一週以上
活躍度
停滯
描述清晰度
基本清楚
新手友好度
30/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。