dotnet / dotnet/command-line-api

Shell Completions

Ouverte
#2,425 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Area-Completions enhancement
Langage dominant
C#
Étoiles
3.7k
Forks
428
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

I've just caught up on [the last community standup](https://www.youtube.com/watch?v=SzpFCVg3JbA) and was interested to hear the direction for completions, and wanted to share how I'm solving this today.

First off, I love the _idea_ of the automagic self-describing directives based completions today (dotnet-suggest), however as was mentioned this is slow (although very workable when AOTing). I abandoned this approach in the end mostly because:
* implementation was very buggy, to the point it wouldn't work in many scenarios
* shell support was lacking
* Fish allows for a better experience than just "here is are the valid tokens you can use here", it can show them in a grid with descriptions, which again wasn't supported with the dotnet-suggest approach.

So what I do for my internal tool (can't share the code sorry) is have a separate file that has the grammar of the command line in, and using a tool ([complgen](https://github.com/adaszko/complgen)) to produce the per-shell scripts. I have the outputs of these then embedded my tool, so I can say `jaz completions fish` (the tool is named jaz) and it will output the `fish` shell snipped. This plays well with eco-system tools like homebrew ([example](https://github.com/Homebrew/homebrew-core/blob/a0db09dc6d6d7188ead73f5aea85434b1979fbbe/Formula/g/gh.rb#L38)).

Here is what my usage grammar looks like:
```
jaz []... [];
jaz [];

::= info "About jaz"
| clear "Remove credentials from your profile" []
| doctor "Perform checkup to diagnose any issues"
| logout "Logout of SSO sessions"
| whoami "Get the caller ID of the current session" [] []
| update-metadata "Update the environment metadata"
| list-profiles "List session profiles"
| generate-profiles "Generate SSO profiles"
;

::= --sso-session "The AWS SSO session to use"
| --account-id "The AWS account ID to use"
| --role "The AWS role to use"
| --region "The AWS region to use"
|
| --version "Show version information"
;

::= --show-role-arn "Show the role ARN";

::= --profile "The AWS profile to use" ;
::= --profile "The AWS profile to use" ;

::= {{{ jaz list-profiles --include-all }}};
::= {{{ jaz list-profiles }}};

::= (-h | --help) "Show help and usage information";
```

You can see this supports calling back into itself for completions (see ``), this is awesome because I get nice completions across all shells, and it's fast because it's static, but I get the dynamic behaviours when I want them.

I'm not suggesting that this _exact_ tool/grammar be selected as the approach, but as a general pattern I think this is really powerful yet simple for developers.

image

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Aucun fichier du dépôt, test ou point d’entrée de l’implémentation n’est identifié. Commencez par examiner l’architecture de complétion existante et l’approche dotnet-suggest, puis comparez-les à la grammaire proposée et au modèle de génération par shell ; la tâche sera considérée comme terminée lorsqu’une conception approuvée et un périmètre défini pour une implémentation de complétion seront établis.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
csharp, shell
Domaine
cli
Type d'issue
Fonctionnalité
Difficulté
5/5
Temps estimé
Plus d'une semaine
Activité
À l'abandon
Clarté
À clarifier
Accessibilité débutants
25/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.