From ecbc775d3b4d8874786738fa4f342e6796446ff0 Mon Sep 17 00:00:00 2001 From: gifnksm Date: Thu, 2 Jan 2025 11:35:14 +0900 Subject: [PATCH] fix(nu): Set argument type based on `ValueHint` - Modified `append_value_completion_and_help` to set argument type to `path` for `ValueHint::AnyPath`, `ValueHint::FilePath`, and `ValueHint::DirPath`, and to `string` for other `ValueHint`s. - Updated test snapshots to reflect the changes in argument types. --- clap_complete_nushell/src/lib.rs | 19 ++++++++++++++++++- .../tests/snapshots/feature_sample.nu | 2 +- .../nu/.config/nushell/completions/test.nu | 8 ++++---- .../tests/snapshots/special_commands.nu | 2 +- .../tests/snapshots/sub_subcommands.nu | 2 +- .../tests/snapshots/value_hint.nu | 8 ++++---- 6 files changed, 29 insertions(+), 12 deletions(-) diff --git a/clap_complete_nushell/src/lib.rs b/clap_complete_nushell/src/lib.rs index e7f064e2d4a..b95a835e526 100644 --- a/clap_complete_nushell/src/lib.rs +++ b/clap_complete_nushell/src/lib.rs @@ -23,6 +23,7 @@ #![warn(clippy::print_stdout)] use clap::builder::StyledStr; +use clap::ValueHint; use clap::{builder::PossibleValue, Arg, ArgAction, Command}; use clap_complete::Generator; @@ -65,7 +66,23 @@ fn append_value_completion_and_help( .unwrap_or(false); if takes_values { - s.push_str(": string"); + let nu_type = match arg.get_value_hint() { + ValueHint::Unknown => "string", + ValueHint::Other => "string", + ValueHint::AnyPath => "path", + ValueHint::FilePath => "path", + ValueHint::DirPath => "path", + ValueHint::ExecutablePath => "path", + ValueHint::CommandName => "string", + ValueHint::CommandString => "string", + ValueHint::CommandWithArguments => "string", + ValueHint::Username => "string", + ValueHint::Hostname => "string", + ValueHint::Url => "string", + ValueHint::EmailAddress => "string", + _ => "string", + }; + s.push_str(format!(": {nu_type}").as_str()); if !possible_values.is_empty() { s.push_str(format!(r#"@"nu-complete {} {}""#, name, arg.get_id()).as_str()); diff --git a/clap_complete_nushell/tests/snapshots/feature_sample.nu b/clap_complete_nushell/tests/snapshots/feature_sample.nu index 78e772bc7ea..eb081b9b4de 100644 --- a/clap_complete_nushell/tests/snapshots/feature_sample.nu +++ b/clap_complete_nushell/tests/snapshots/feature_sample.nu @@ -6,7 +6,7 @@ module completions { # Tests completions export extern my-app [ - file?: string # some input file + file?: path # some input file --config(-c) # some config file with another line --conf # some config file with another line -C # some config file with another line diff --git a/clap_complete_nushell/tests/snapshots/home/static/test/nu/.config/nushell/completions/test.nu b/clap_complete_nushell/tests/snapshots/home/static/test/nu/.config/nushell/completions/test.nu index 03c5cd6bd1b..ac1e050f667 100644 --- a/clap_complete_nushell/tests/snapshots/home/static/test/nu/.config/nushell/completions/test.nu +++ b/clap_complete_nushell/tests/snapshots/home/static/test/nu/.config/nushell/completions/test.nu @@ -178,10 +178,10 @@ module completions { --choice: string@"nu-complete test hint choice" --unknown: string --other: string - --path(-p): string - --file(-f): string - --dir(-d): string - --exe(-e): string + --path(-p): path + --file(-f): path + --dir(-d): path + --exe(-e): path --cmd-name: string --cmd(-c): string command_with_args?: string diff --git a/clap_complete_nushell/tests/snapshots/special_commands.nu b/clap_complete_nushell/tests/snapshots/special_commands.nu index f74a3c867b4..0551531b3f7 100644 --- a/clap_complete_nushell/tests/snapshots/special_commands.nu +++ b/clap_complete_nushell/tests/snapshots/special_commands.nu @@ -6,7 +6,7 @@ module completions { # Tests completions export extern my-app [ - file?: string # some input file + file?: path # some input file --config(-c) # some config file with another line --conf # some config file with another line -C # some config file with another line diff --git a/clap_complete_nushell/tests/snapshots/sub_subcommands.nu b/clap_complete_nushell/tests/snapshots/sub_subcommands.nu index 7b0570f876a..2f56ca6d46c 100644 --- a/clap_complete_nushell/tests/snapshots/sub_subcommands.nu +++ b/clap_complete_nushell/tests/snapshots/sub_subcommands.nu @@ -6,7 +6,7 @@ module completions { # Tests completions export extern my-app [ - file?: string # some input file + file?: path # some input file --config(-c) # some config file with another line --conf # some config file with another line -C # some config file with another line diff --git a/clap_complete_nushell/tests/snapshots/value_hint.nu b/clap_complete_nushell/tests/snapshots/value_hint.nu index 2cc0b5ab800..f27849a5463 100644 --- a/clap_complete_nushell/tests/snapshots/value_hint.nu +++ b/clap_complete_nushell/tests/snapshots/value_hint.nu @@ -8,10 +8,10 @@ module completions { --choice: string@"nu-complete my-app choice" --unknown: string --other: string - --path(-p): string - --file(-f): string - --dir(-d): string - --exe(-e): string + --path(-p): path + --file(-f): path + --dir(-d): path + --exe(-e): path --cmd-name: string --cmd(-c): string command_with_args?: string