mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 14:52:33 +00:00
fix: escape quotes when string has whitespace
This commit is contained in:
parent
c6fe49aba5
commit
50aefdb9b3
3 changed files with 11 additions and 9 deletions
11
README.md
11
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
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue