Skip to content

Commit

Permalink
Merge pull request #5865 from gifnksm/nushell-completion-value-types
Browse files Browse the repository at this point in the history
fix(nu): Set argument type based on `ValueHint`
  • Loading branch information
epage authored Jan 2, 2025
2 parents 6784054 + ecbc775 commit d74b793
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 12 deletions.
19 changes: 18 additions & 1 deletion clap_complete_nushell/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion clap_complete_nushell/tests/snapshots/feature_sample.nu
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion clap_complete_nushell/tests/snapshots/special_commands.nu
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion clap_complete_nushell/tests/snapshots/sub_subcommands.nu
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions clap_complete_nushell/tests/snapshots/value_hint.nu
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d74b793

Please sign in to comment.