clap icon indicating copy to clipboard operation
clap copied to clipboard

Nushell completions should use `glob` type for paths

Open KAAtheWiseGit opened this issue 7 months ago • 1 comments

Please complete the following tasks

Rust Version

rustc 1.80.0 (051478957 2024-07-21) (Alpine Linux 1.80.0-r0)

Clap Version

4.4.6 (4.5.3 for clap_complete_nushell)

Minimal reproducible code

use clap::{CommandFactory, Parser};
use clap_complete::generate;
use clap_complete_nushell::Nushell;

use std::path::PathBuf;

#[derive(Parser)]
pub struct Options {
    path: PathBuf,

    rest: Vec<PathBuf>,
}

fn main() {
    let mut cmd = Options::command();
    generate(Nushell, &mut cmd, "sd", &mut std::io::stdout());
}

Steps to reproduce the bug with the above code

cargo run

Actual Behaviour

The following completion is generated:

module completions {

  export extern sd [
    path: string
    ...rest: string
    --help(-h)                # Print help
  ]

}

export use completions *

Expected Behaviour

  • Arguments with type PathBuf should have the path type in the completions, so that the native path completion works.
  • Arguments with type Vec<PathBuf> should have the glob type, otherwise globbing breaks: sd a * will return an error, because path * doesn't exist.

Additional Context

No response

Debug Output

[clap_builder::builder::command]Command::_build: name="compl"
[clap_builder::builder::command]Command::_propagate:compl
[clap_builder::builder::command]Command::_check_help_and_version:compl expand_help_tree=true
[clap_builder::builder::command]Command::long_help_exists
[clap_builder::builder::command]Command::_check_help_and_version: Building default --help
[clap_builder::builder::command]Command::_propagate_global_args:compl
[clap_builder::builder::debug_asserts]Command::_debug_asserts
[clap_builder::builder::debug_asserts]Arg::_debug_asserts:path
[clap_builder::builder::debug_asserts]Arg::_debug_asserts:rest
[clap_builder::builder::debug_asserts]Arg::_debug_asserts:help
[clap_builder::builder::debug_asserts]Command::_verify_positionals
[clap_builder::builder::command]Command::_build_bin_names
[ clap_builder::output::usage]Usage::get_required_usage_from: incls=[], matcher=false, incl_last=true
[ clap_builder::output::usage]Usage::get_required_usage_from: unrolled_reqs=["path"]
[ clap_builder::output::usage]Usage::get_required_usage_from:iter:"path" arg is_present=false
[ clap_builder::output::usage]Usage::get_required_usage_from: ret_val=[StyledStr("<PATH>")]

KAAtheWiseGit avatar Jul 28 '24 18:07 KAAtheWiseGit