commandlineparser / commandlineparser/commandline

Does the Options attribute class really need to be sealed?

Aperta
#859 3 commenti 1 reazione 0 assegnatari Vedi su GitHub
awaiting response
Lingua principale
C#
Stelle
4.8k
Fork
478
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

I have been using CommandLineParser for a while now (and it's changed how I build tools -- thank you!) including in a program with ~50 Verbs (and growing), and since many of the Verbs take common options, I was hoping to extend `Options` to provide common handling of them.

Simple example: if 15 Verbs take a `LogFile` option, each of which has a long name ("log-file") and a help description, I can do this now by constant strings to keep them consistent, but if I were able to do:

```
[AttributeUsage(AttributeTargets.Property)]
public class LogFileOptionAttribute : OptionAttribute
{
public LogFileOptionAttribute(bool required = false)
: base("log-file") // I don't use short option names for anything
{
HelpText = "Name of the logfile to use for blah blah blah";
Required = required;
}
}
```
and then adorn the actual option with:
```
public class BlahOptions {
...
[LogFileOption]
public string LogFileName {get ; set; }
...
}
```
I have easily a dozen of these common options. It's not a huge deal to create constant strings:
```
[Option(OPTION_LOGFILE_NAME, HelpText = OPTION_LOGFILE_HELPTEXT)]
```
but adding this level of abstraction would be more convenient.

If there's a good reason for this class to be sealed, then so be it, but mine doesn't feel like a ridiculous use case. I may well get to 100 verbs for this tool by the time I'm done.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Non sono indicati file o test. Inizia individuando la dichiarazione C# Options/OptionAttribute e il relativo modificatore sealed, quindi esamina come vengono utilizzati gli attributi e come sono coperti dai test. Il lavoro è completato quando il progetto ha preso una decisione esplicita e verificata sul supporto degli attributi option derivati, con i corrispondenti aggiornamenti dell’API e dei test se la decisione è positiva.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
csharp
Ambito
cli
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.