dotnet / dotnet/command-line-api

Shell Completions

オープン
#2,425 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る
Area-Completions enhancement
主要言語
C#
スター
3.7k
フォーク
428
PR マージ指標
30日以内にマージされた PR はありません

説明

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

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

No repository files, tests, or implementation entry points are identified. Start by reviewing the existing completion architecture and the dotnet-suggest approach, then compare them with the proposed grammar and per-shell generation pattern; done requires an agreed design and defined scope for a completion implementation.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
csharp, shell
領域
cli
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。