dotnet / dotnet/command-line-api

(Small) API Suggestion: Make SetHandler return parent instance

Aperta
#1,702 0 commenti 3 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
C#
Stelle
3.7k
Fork
428
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

At the moment, with the new API style the recommended approach is something like:
```
var subCommand = new Command("subcommand")
{
new Option("-x")
};

var rootCommand = new RootCommand
{
subCommand
};

subCommand.SetHandler(string x => {
//Do stuff
});

```

But this can be quite terse, at the moment the `SetHandler` methods return `void` - if it could instead return the instance of the command the API comes alot more fluent and shorter:
```
var rootCommand = new RootCommand
{
new Command("subcommand")
{
new Option("-x")
}
.SetHandler((string x) => {
//Do stuff
});
};
```

Or potentially extend the `Add` methods on `Command` to include the `Func<>`/Command handler
```
var rootCommand = new RootCommand
{
new Command("subcommand")
{
new Option("-x"),
(string x) => {
//Do stuff
}
};
};
```

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia individuando i metodi SetHandler e la Command API a cui appartengono; l’issue non indica alcun file o test. Determina gli overload applicabili e se restituire il comando padre supporta gli esempi fluent senza modificare il comportamento degli handler; il lavoro è completato quando la forma fluent richiesta è supportata in modo coerente.

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

Valutazione

Stack tecnologico
csharp
Ambito
cli
Tipo di issue
Funzionalità
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.