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

Nushell completions should use glob type for paths #5605

Open
2 tasks done
KAAtheWiseGit opened this issue Jul 28, 2024 · 1 comment
Open
2 tasks done

Nushell completions should use glob type for paths #5605

KAAtheWiseGit opened this issue Jul 28, 2024 · 1 comment
Labels
A-completion Area: completion generator C-enhancement Category: Raise on the bar on expectations

Comments

@KAAtheWiseGit
Copy link

KAAtheWiseGit commented Jul 28, 2024

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 KAAtheWiseGit added the C-bug Category: Updating dependencies label Jul 28, 2024
@epage epage added C-enhancement Category: Raise on the bar on expectations A-completion Area: completion generator and removed C-bug Category: Updating dependencies labels Jul 29, 2024
@epage
Copy link
Member

epage commented Jul 29, 2024

clap_complete_nushell does not yet have support for ValueHint. Someone is welcome to contribute it and/or add Rust-native nushell completion support (see also #3166).

Note: we implicitly set the ValueHint based on an Arg being a PathBuf, see

/// Get the value hint of this argument
pub fn get_value_hint(&self) -> ValueHint {
self.value_hint.unwrap_or_else(|| {
if self.is_takes_value_set() {
let type_id = self.get_value_parser().type_id();
if type_id == AnyValueId::of::<std::path::PathBuf>() {
ValueHint::AnyPath
} else {
ValueHint::default()
}
} else {
ValueHint::default()
}
})
}

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-enhancement Category: Raise on the bar on expectations
Projects
None yet
Development

No branches or pull requests

2 participants