commandlineparser / commandlineparser/commandline

Support for implicit empty string

Offen
#765 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
C#
Sterne
4.8k
Forks
478
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.