Skip to content

Commit ecbc775

Browse files
committed
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.
1 parent 6784054 commit ecbc775

File tree

6 files changed

+29
-12
lines changed

6 files changed

+29
-12
lines changed

clap_complete_nushell/src/lib.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#![warn(clippy::print_stdout)]
2424

2525
use clap::builder::StyledStr;
26+
use clap::ValueHint;
2627
use clap::{builder::PossibleValue, Arg, ArgAction, Command};
2728
use clap_complete::Generator;
2829

@@ -65,7 +66,23 @@ fn append_value_completion_and_help(
6566
.unwrap_or(false);
6667

6768
if takes_values {
68-
s.push_str(": string");
69+
let nu_type = match arg.get_value_hint() {
70+
ValueHint::Unknown => "string",
71+
ValueHint::Other => "string",
72+
ValueHint::AnyPath => "path",
73+
ValueHint::FilePath => "path",
74+
ValueHint::DirPath => "path",
75+
ValueHint::ExecutablePath => "path",
76+
ValueHint::CommandName => "string",
77+
ValueHint::CommandString => "string",
78+
ValueHint::CommandWithArguments => "string",
79+
ValueHint::Username => "string",
80+
ValueHint::Hostname => "string",
81+
ValueHint::Url => "string",
82+
ValueHint::EmailAddress => "string",
83+
_ => "string",
84+
};
85+
s.push_str(format!(": {nu_type}").as_str());
6986

7087
if !possible_values.is_empty() {
7188
s.push_str(format!(r#"@"nu-complete {} {}""#, name, arg.get_id()).as_str());

clap_complete_nushell/tests/snapshots/feature_sample.nu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module completions {
66

77
# Tests completions
88
export extern my-app [
9-
file?: string # some input file
9+
file?: path # some input file
1010
--config(-c) # some config file with another line
1111
--conf # some config file with another line
1212
-C # some config file with another line

clap_complete_nushell/tests/snapshots/home/static/test/nu/.config/nushell/completions/test.nu

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,10 @@ module completions {
178178
--choice: string@"nu-complete test hint choice"
179179
--unknown: string
180180
--other: string
181-
--path(-p): string
182-
--file(-f): string
183-
--dir(-d): string
184-
--exe(-e): string
181+
--path(-p): path
182+
--file(-f): path
183+
--dir(-d): path
184+
--exe(-e): path
185185
--cmd-name: string
186186
--cmd(-c): string
187187
command_with_args?: string

clap_complete_nushell/tests/snapshots/special_commands.nu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module completions {
66

77
# Tests completions
88
export extern my-app [
9-
file?: string # some input file
9+
file?: path # some input file
1010
--config(-c) # some config file with another line
1111
--conf # some config file with another line
1212
-C # some config file with another line

clap_complete_nushell/tests/snapshots/sub_subcommands.nu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module completions {
66

77
# Tests completions
88
export extern my-app [
9-
file?: string # some input file
9+
file?: path # some input file
1010
--config(-c) # some config file with another line
1111
--conf # some config file with another line
1212
-C # some config file with another line

clap_complete_nushell/tests/snapshots/value_hint.nu

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ module completions {
88
--choice: string@"nu-complete my-app choice"
99
--unknown: string
1010
--other: string
11-
--path(-p): string
12-
--file(-f): string
13-
--dir(-d): string
14-
--exe(-e): string
11+
--path(-p): path
12+
--file(-f): path
13+
--dir(-d): path
14+
--exe(-e): path
1515
--cmd-name: string
1616
--cmd(-c): string
1717
command_with_args?: string

0 commit comments

Comments
 (0)