dotnet / dotnet/command-line-api
dotnet-suggest: Completion when launching global tool via "dotnet"
- Dominant language
- C#
- Stars
- 3.7k
- Forks
- 428
- PR merge metrics
- No merged PRs in 30d
Description
Tools that have a `dotnet-` prefix (e.g. `dotnet-monitor`) can be invoked via the main `dotnet` executable. I.e. you can launch a tool named `dotnet-monitor` by running `dotnet-monitor` or `dotnet monitor` (note the space). The latter simply results in `dotnet` launching the `dotnet-monitor` tool indirectly (so it's clearly less efficient), but from the user's perspective you get the same result.
The `dotnet-suggest` tool however only appears to successfully provide suggestions for tools that are directly invoked, even though such tools register both their potential entrypoints in `.dotnet-suggest-registration.txt`. I took a look at the code and the relevant part seems to be the `FormatSuggestionArguments` method in the `SuggestionDispatcher` class.
If the executable is `dotnet` it uses a different code path that strips the second token before passing it through to the target executable for suggestions. Some examples to help illustrate:
- `dotnet monitor` -> invokes `dotnet [suggest:0] ""`
- `dotnet monitor config` -> invokes `dotnet [suggest:6] "config"`
- `dotnet monitor config show` -> invokes `dotnet [suggest:11] "config show"`
I don't understand what this logic is trying to do. Is there some subtlety I'm missing here? Even if I manually send what I think should be the "correct" args to `dotnet` I still don't get back correct completions, e.g. `dotnet [suggest:13] "monitor config"`, so it's unclear if this is meant to work at all, or ever did. But in that case, why do tools using `System.CommandLine` register their `dotnet` aliases?
I am very confused ...
Contributor guide
Assessment
This issue has not been assessed yet.