dotnet / dotnet/command-line-api

CompletionAction doesn't display all possible matches when the commandline matches a command name or alias

Open
#2,242 1 comment 0 reactions 0 assignees View on GitHub
Area-Completions
Dominant language
C#
Stars
3.7k
Forks
428
PR merge metrics
No merged PRs in 30d

Description

Tab completions are wrong when the command line text matches a command name or alias. With a cli with a lot commands/aliases this makes tab completion painful because you might hit an alias and then it doesn't go through other commands.

CompletionAction runs this parse:

```
var completionParseResult = parseResult.RootCommandResult.Command.Parse(commandLineToComplete, parseResult.Configuration);
```
If it matches a command or alias, the completionParseResult is set to that command and GetCompletions is run jsut for that specific command.

Example below. When running [suggest:1] "t" I would expect it to show me "test-log-levels" and "test-log-colors" but it is just showing "--option1" which is also weird considering if it was the full completions for "t" it would be the following (what it displays with [suggest:2] "t")

```
--help
--option1
-?
-h
-o1
/?
/h
```

```
void Main()
{
CliRootCommand cliRootCommand = new CliRootCommand();
CliCommand command = new CliCommand("test-log-levels", "Show use of the different log levels by printing a log message at each level");
command.Aliases.Add("t");
command.Options.Add(new CliOption("--option1", "-o1"));
CliCommand command2 = new CliCommand("test-log-colors", "Show use of the different log levels by printing a log message at each level");
cliRootCommand.Subcommands.Add(command);
cliRootCommand.Subcommands.Add(command2);

string[] args = new string[] { "[suggest:1]", "t"};
var cliConfiguration = new CliConfiguration(cliRootCommand) { };

var parseResult = cliConfiguration.Parse(args);
int exitCode = parseResult.InvokeAsync().Result;
}
```

Planning to look into this a bit more, initial thoughts is the parsing for suggest should be different, "t" with position 1 it shouldn't just parse to the specific command, "t" position 2 should though since there is a space after.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.