Skip to content
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

Hyphens missing from listItemText in generated PowerShell autocomplete scripts #5606

Closed
2 tasks done
Mixu78 opened this issue Jul 29, 2024 · 0 comments · Fixed by #5610
Closed
2 tasks done

Hyphens missing from listItemText in generated PowerShell autocomplete scripts #5606

Mixu78 opened this issue Jul 29, 2024 · 0 comments · Fixed by #5610
Labels
A-completion Area: completion generator C-bug Category: Updating dependencies E-easy Call for participation: Experience needed to fix: Easy / not much

Comments

@Mixu78
Copy link
Contributor

Mixu78 commented Jul 29, 2024

Please complete the following tasks

Rust Version

rustc 1.80.0 (051478957 2024-07-21)

Clap Version

4.5.11

Minimal reproducible code

use std::io;

use clap::{Arg, Command};
use clap_complete::{generate, Shell};

fn main() {

    let mut cmd = Command::new("dummy")
        .arg(Arg::new("foo").long("foo"))
        .subcommand(Command::new("foo"));

    generate(Shell::PowerShell, &mut cmd, "dummy", &mut io::stdout());
}

Steps to reproduce the bug with the above code

cargo run

or to source the script:

Invoke-Expression (cargo run | Out-String)

Actual Behaviour

The generated completion script is missing hyphens in the CompletionResult::new listItemText parameter for all options. This is at best confusing, leading to options being listed without their hyphens when attempting to complete them, and at worst causes collisions making it impossible to complete a subcommand with the same name as an option without first typing a character. Completion scripts for other shells seem to include hyphens correctly.

A snippet of the completion script generated by the reproduction code:

'dummy' {
            [CompletionResult]::new('--foo', 'foo', [CompletionResultType]::ParameterName, 'foo')
            [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
            [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
            [CompletionResult]::new('foo', 'foo', [CompletionResultType]::ParameterValue, 'foo')
            [CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)')     
            break
        }

In the snippet above the missing hyphens cause option --foo and subcommand foo to collide. The option --foo is displayed as "foo" when completing with no input other than the command, with the subcommand foo being uncompletable. foo is correctly completed only when at least the first letter has been typed.

Expected Behaviour

The generated completion script should have hyphens in both the completionText and listItemText parameters in the CompletionResult constructor call:

'dummy' {
            [CompletionResult]::new('--foo', '--foo', [CompletionResultType]::ParameterName, 'foo')
            [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help')
            [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help')
            [CompletionResult]::new('foo', 'foo', [CompletionResultType]::ParameterValue, 'foo')
            [CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)')     
            break
        }

Additional Context

Lines 134 and 145 in clap_complete/src/shells/powershell.rs seem to be causing this.

Debug Output

No response

@Mixu78 Mixu78 added the C-bug Category: Updating dependencies label Jul 29, 2024
@epage epage added A-completion Area: completion generator E-easy Call for participation: Experience needed to fix: Easy / not much labels Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-completion Area: completion generator C-bug Category: Updating dependencies E-easy Call for participation: Experience needed to fix: Easy / not much
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants