-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Utilize ShellName and Add Test to Enable Completions W/out Shell on Unix #48918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
I confirmed the proposal by Kalle, dotnet#48420 that the shellMap that gets provided is a default list of shell names like "fish" or "zsh" that are stored in the Shell Env Var. They are all lowercase in the shell map.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR aims to enable static completions to work in scenarios where a shell has not been specified on Unix by leveraging a default mapping of lowercase shell names. Key changes include:
- Adding a test (ShellDiscoveryTests.cs) to validate that the completions command works without an explicit shell.
- Updating CompletionsCommand.cs to convert the shell name to lowercase before lookup in the shell map.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/dotnet.Tests/CompletionTests/ShellDiscoveryTests.cs | Adds a new test ensuring completions work even without a specified shell. |
| src/System.CommandLine.StaticCompletions/CompletionsCommand.cs | Normalizes the shell name to lowercase to match against the shell map. |
|
|
||
| public class ShellDiscoveryTests() | ||
| { | ||
| [Fact] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe parameterize this test with the shell names and set the SHELL env var before each run so we can easily test all of our shell experiences??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a great point -- I think this test should be ok since it works in general on any generic shell. If we had more capacity I would probably add this to the test, but not going to prioritize it right now. Thank you for reviewing
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
|
|
||
|
|
||
| using System.CommandLine.StaticCompletions.Shells; | ||
| using Microsoft.DotNet.Cli.Commands.BuildServer.Shutdown; |
Copilot
AI
Oct 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The using statement for Microsoft.DotNet.Cli.Commands.BuildServer.Shutdown appears unused in this test class. Unused using directives should be removed.
| using Microsoft.DotNet.Cli.Commands.BuildServer.Shutdown; |
|
|
||
| using System.CommandLine.StaticCompletions.Shells; | ||
| using Microsoft.DotNet.Cli.Commands.BuildServer.Shutdown; | ||
| using Microsoft.Extensions.Options; |
Copilot
AI
Oct 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The using statement for Microsoft.Extensions.Options appears unused in this test class. Unused using directives should be removed.
| using Microsoft.Extensions.Options; |
|
@copilot The new test used to work but now fails with: |
Co-authored-by: Copilot <[email protected]>
| var shellName = Path.GetFileName(shellPath); | ||
| if (shellMap.TryGetValue(shellPath, out var shellProvider)) | ||
| var shellName = Path.GetFileName(shellPath).ToLower(); | ||
| if (shellMap.TryGetValue(shellName, out var shellProvider)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The .ToLower() call should not be necessary, because shellMap is using StringComparer.OrdinalIgnoreCase:
| public CompletionsCommand(IEnumerable<IShellProvider>? supportedShells = null, string commandName = "completions", string? commandDescription = null) : this((supportedShells ?? DefaultShells).ToDictionary(s => s.ArgumentName, StringComparer.OrdinalIgnoreCase), commandName, commandDescription ?? Strings.CompletionsCommand_Description) |
… unless you specifically want culture-specific case folding here, e.g. FISH to fısh in a Turkish culture. But that seems more likely to hurt than help because none of the known shell names includes a dotless ı.
| { | ||
| ParseResult result = Parser.Parse(["dotnet", "completions", "script"]); | ||
| result.Errors.Should().BeEmpty(); | ||
| result.GetValue<IShellProvider>("@CompletionsCommand_ShellArgument_Description").Should().NotBeNull(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this at-sign syntax "@CompletionsCommand_ShellArgument_Description"? Shouldn't the argument be simply "shell", matching the Argument<IShellProvider> construction here:
| var shellArg = new Argument<IShellProvider>("shell") |
I confirmed the proposal by Kalle, which resolves #48420 and confirmed that the shellMap that gets provided is a default list of shell names like "fish" or "zsh" that are stored in the Shell Env Var. They are all lowercase in the shell map.