dotnet / dotnet/command-line-api

Better tab completion for options with 0 or 1+ arity

Open
#1,495 2 comments 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

In case, the option may have 0 or 1 argument, allow completion for other symbols on the same level after option name.
Example:

```csharp
Command updateCommand = new Command("update")
{
new Option("--nuget-source")
{
Arity = new ArgumentArity(1, 10)
},
new Option("--interactive")
};

var parseResult = updateCommand.Parse("update --interactive ");
var suggestions = parseResult.GetSuggestions().ToArray();

Assert.Contains("True", suggestions); //completed argument for boolean option
Assert.Contains("False", suggestions); //completed argument for boolean option
Assert.Contains("--nuget-source", suggestions); //next option -fails now, though allowed syntax
}
```

In case, the option may have 1+ argument, allow completion for other symbols on the same level after minimum amount of elements is written (1).

Example:
```csharp
Command updateCommand = new Command("update")
{
new Option("--nuget-source")
{
Arity = new ArgumentArity(1, 10)
},
new Option("--interactive")
};

var parseResult = updateCommand.Parse("update --nuget-source arg1 ");
var suggestions = parseResult.GetSuggestions().ToArray();

Assert.Contains("--interactive", suggestions); //fails now, though allowed syntax
}
```

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.