commandlineparser / commandlineparser/commandline

How to add constraints to an int option?

Offen
#905 1 Kommentar 6 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

Is it possible to set constraints to an int option so that it have min and max allowed values? I think that's a pretty common scenario, but the following fails:

```csharp
[Option('q', "quality", Default = 80, Min = 1, Max = 100)]
public int Quality { get; set; }

```
With this exception: `System.InvalidOperationException: Scalar option specifications do not support range specification.`

If the library does not provide this functionality how would I implement it on my own and still play nicely with the auto help and error messages that the library automatically outputs on invalid input?

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

Beginne damit, dem Option-Attribut und dem Pfad der Spezifikation für skalare Optionen zu folgen, der die Ausnahme für die Bereichsspezifikation auslöst. Untersuche anschließend, wie die Bibliothek Hilfe und Fehler für ungültige Eingaben erzeugt; abgeschlossen ist die Aufgabe, wenn ganzzahlige Min-/Max-Einschränkungen unterstützt werden und die bestehenden Ausgaben konsistent bleiben.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
csharp
Bereich
cli
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

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