Skip to content

Commit 0e7752e

Browse files
committed
fix(builder): Quote empty default values
1 parent d00bbfd commit 0e7752e

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

clap_builder/src/util/escape.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ impl<'s> Escape<'s> {
88
}
99

1010
pub(crate) fn to_cow(self) -> Cow<'s, str> {
11-
if self.0.contains(char::is_whitespace) {
11+
if self.0.is_empty() || self.0.contains(char::is_whitespace) {
1212
Cow::Owned(format!("{:?}", self.0))
1313
} else {
1414
Cow::Borrowed(self.0)
@@ -18,7 +18,7 @@ impl<'s> Escape<'s> {
1818

1919
impl std::fmt::Display for Escape<'_> {
2020
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21-
if self.0.contains(char::is_whitespace) {
21+
if self.0.is_empty() || self.0.contains(char::is_whitespace) {
2222
std::fmt::Debug::fmt(self.0, f)
2323
} else {
2424
self.0.fmt(f)

tests/builder/help.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2044,7 +2044,7 @@ fn empty_default_value() {
20442044
Usage: default [OPTIONS]
20452045
20462046
Options:
2047-
--arg <argument> Pass an argument to the program. [default: ]
2047+
--arg <argument> Pass an argument to the program. [default: ""]
20482048
-h, --help Print help
20492049
-V, --version Print version
20502050

0 commit comments

Comments
 (0)