commandlineparser / commandlineparser/commandline
Does the Options attribute class really need to be sealed?
- Langage dominant
- C#
- Étoiles
- 4.8k
- Forks
- 478
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
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.
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Piste de recherche
Aucun fichier ni test n’est nommé. Commencez par localiser la déclaration C# Options/OptionAttribute et son modificateur sealed, puis examinez comment les attributs sont utilisés et couverts par les tests. C’est terminé lorsque le projet dispose d’une décision explicite et revue quant à la prise en charge des attributs d’option dérivés, avec les mises à jour correspondantes de l’API et des tests si cette décision est positive.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- csharp
- Domaine
- cli
- Type d'issue
- Fonctionnalité
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100