dotnet / dotnet/command-line-api

It should be dirt simple to replace or augment CliActions

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

Descrizione

`CliAction` is a great replacement for the old middleware pipeline. The initial vision CLI authors extending it by _just implement a conditional_ is excellent. However, `InvocationPipelin.Invoke` and `InvocationPipelin.InvokeAsync` have significant doe and we can be fairly sure our implementation will evolve.

For example, the additions in #2147 improve the design by offering pre-actions. The code is now getting complicated and `InvokeAsync` is already quite complicated. All proper `Invoke` implementations need to run the same operations as these two methods. However, if we do this by asking CLI authors to grab the parse result and implement their own `Invoke` or `InvokeAsync`, they are forced to copy this code.

If this CLI author does not correctly implement `Invoke` and/or `InvokeAsync`, key functionality will be inconsistent with the ecosystem. Already present (assuming #2147 is merged): Environment variables will not be set and cancellation may not be done correctly.

The fix is to allow the user to supply the conditional to run at the point in `InvocationPipelin.Invoke` and `InvocationPipelin.InvokeAsync` where `parseResult.CliAction.Invoke(parseResult)` is called. This way the user leverages consistent ecosystem behavior now and in the future.

With this change it would remain possible to avoid grab the parse result and do whatever you want, but it would rarely be needed.

The reasons to avoid CLI author’s copying or replacing `InvocationPipelin.Invoke` and `InvocationPipelin.InvokeAsync` are:

• This code is complicated, so the user may get it wrong. This is especially true with InvokeAsync
• We are very likely to change this code, such as adding post actions. Post actions would simply not work if the programmer copied an earlier version of the InvocationPipeline methods
o While creating a post action is an advanced feature, using post actions is not
o We have these methods internal because they may change
• Failing to isolate the code we have strong opinions on from that the user has strong opinions on leaves users with code that is difficult to maintain

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia individuando InvocationPipelin.Invoke e InvocationPipelin.InvokeAsync, quindi esamina la chiamata parseResult.CliAction.Invoke(parseResult) in ciascun metodo. Traccia la gestione esistente delle variabili d’ambiente e dell’annullamento e verifica che i chiamanti possano fornire una condizione senza copiare il comportamento di invocazione condiviso. Il lavoro è completato quando entrambi i percorsi di invocazione preservano tale comportamento dell’ecosistema, consentendo al contempo di sostituire o ampliare la condizione.

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

Valutazione

Stack tecnologico
csharp
Ambito
cli
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.