clap-rs / clap

A full featured, fast Command Line Argument Parser for Rust
docs.rs/clap
Apache License 2.0
13.66k stars 1.02k forks source link

Powershell completions not working with empty help string. #5341

Open LucasLehmann opened 5 months ago

LucasLehmann commented 5 months ago

I came across a problem with the uutils coreutils package where the powershell completions didnt work, https://github.com/uutils/coreutils/issues/5933, and was directed here. I discovered this is because in the generated ps1 file the line [CompletionResuIt]::new('seq', 'seq', [CompletionResultType]::ParameterValue, '') exists, this line seems to cause the completions to fail and fall back on completing files, i also noticed this is not an issue and everything works as intended when adding something here, be it ' ' or anything else. I dont know how this and i have never used clap so i dont know what to do to try to replicate it. But i can duplicate the issue in for example rustups completion by replacing it an empty string in one of the completion elements.

tertsdiepraam commented 5 months ago

Here's a minimal example as cargo script:

#!/usr/bin/env -S cargo +nightly -Zscript

[dependencies] clap = "4.4.18" clap_complete = "4.4.10"


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

fn main() {
    let mut cmd = Command::new("test").subcommand(Command::new("foo").about(""));
    generate(PowerShell, &mut cmd, "test", &mut std::io::stdout());
}

Upon further inspection, I do think we have to fix this in uutils as well, but I think clap_complete should be aware that an empty about breaks completion and fall back to something else.