diff --git a/README.md b/README.md index 133857a0..78bf337e 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Generates [Nushell](https://github.com/nushell/nushell) completions for [`clap`] ### myapp.rs ```rust -use clap::{Arg, ArgAction, Command}; +use clap::{builder::PossibleValue, Arg, ArgAction, Command, ValueHint}; use clap_complete::generate; use clap_complete_nushell::Nushell; use std::io; @@ -25,7 +25,7 @@ fn main() { .about("Tests completions") .arg( Arg::new("file") - .value_hint(clap::ValueHint::FilePath) + .value_hint(ValueHint::FilePath) .help("some input file"), ) .arg( @@ -54,9 +54,7 @@ fn main() { Arg::new("config") .long("config") .action(ArgAction::Set) - .value_parser([clap::builder::PossibleValue::new( - "Lest quotes aren't escaped.", - )]) + .value_parser([PossibleValue::new("Lest quotes aren't escaped.")]) .help("the other case to test"), ), ), @@ -66,7 +64,6 @@ fn main() { } ``` - ### myapp.nu ```nu @@ -98,7 +95,7 @@ module completions { ] def "nu-complete myapp some_cmd sub_cmd config" [] { - [ "Lest quotes aren't escaped." ] + [ "\"Lest quotes aren't escaped.\"" ] } # sub-subcommand diff --git a/src/lib.rs b/src/lib.rs index 22cf7997..780a5979 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -123,7 +123,12 @@ impl<'a, 'b> Argument<'a, 'b> { s.push_str("\n ["); for value in &possible_values { - s.push_str(format!(r#" "{}""#, value.get_name()).as_str()); + let name = value.get_name(); + if name.contains(|c: char| c.is_whitespace()) { + s.push_str(format!(r#" "\"{}\"""#, name).as_str()); + } else { + s.push_str(format!(r#" "{}""#, name).as_str()); + } } s.push_str(" ]\n }\n\n"); diff --git a/tests/snapshots/sub_subcommands.nu b/tests/snapshots/sub_subcommands.nu index a56800b6..abcfac81 100644 --- a/tests/snapshots/sub_subcommands.nu +++ b/tests/snapshots/sub_subcommands.nu @@ -26,7 +26,7 @@ module completions { ] def "nu-complete my-app some_cmd sub_cmd config" [] { - [ "Lest quotes, aren't escaped." "Second to trigger display of options" ] + [ "\"Lest quotes, aren't escaped.\"" "\"Second to trigger display of options\"" ] } # sub-subcommand