diff --git a/clap_builder/src/builder/arg.rs b/clap_builder/src/builder/arg.rs index 5a8b1706922..23c6a9bd0da 100644 --- a/clap_builder/src/builder/arg.rs +++ b/clap_builder/src/builder/arg.rs @@ -4647,6 +4647,7 @@ impl Arg { val_names = vec![val_name; min]; } + let delimiter = self.get_value_delimiter().unwrap_or(' '); debug_assert!(self.is_takes_value_set()); for (n, val_name) in val_names.iter().enumerate() { let arg_name = if self.is_positional() && (num_vals.min_values() == 0 || !required) { @@ -4656,7 +4657,7 @@ impl Arg { }; if n != 0 { - rendered.push(' '); + rendered.push(delimiter); } rendered.push_str(&arg_name); } @@ -4670,6 +4671,11 @@ impl Arg { rendered.push_str("..."); } + if let Some(terminator) = self.get_value_terminator() { + rendered.push(' '); + rendered.push_str(terminator); + } + rendered } diff --git a/clap_builder/src/output/help_template.rs b/clap_builder/src/output/help_template.rs index da08ccd3895..518081e05da 100644 --- a/clap_builder/src/output/help_template.rs +++ b/clap_builder/src/output/help_template.rs @@ -766,6 +766,13 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> { a.default_vals ); + // We might need up to 4 bytes to encode an utf-8 character + let mut buffer = [0u8; 4]; + let delimiter = a + .get_value_delimiter() + .unwrap_or(' ') + .encode_utf8(&mut buffer); + let pvs = a .default_vals .iter() @@ -778,11 +785,21 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> { } }) .collect::>() - .join(" "); + .join(delimiter); spec_vals.push(format!("[default: {pvs}]")); } + if let Some(delimiter) = a.get_value_delimiter() { + debug!("HelpTemplate::spec_vals: Found delimiter...{delimiter:?}"); + spec_vals.push(format!("[value delimiter: {delimiter:?}]")); + } + + if let Some(terminator) = a.get_value_terminator() { + debug!("HelpTemplate::spec_vals: Found terminator...{terminator:?}"); + spec_vals.push(format!("[value terminator: {terminator:?}]")); + } + let als = a .aliases .iter() diff --git a/tests/builder/help.rs b/tests/builder/help.rs index ebb90477271..3696a2f330e 100644 --- a/tests/builder/help.rs +++ b/tests/builder/help.rs @@ -2053,10 +2053,10 @@ fn issue_1052_require_delim_help() { let expected = str![[r#" tests stuff -Usage: test --fake +Usage: test --fake : Options: - -f, --fake some help + -f, --fake : some help [value delimiter: ':'] -h, --help Print help -V, --version Print version @@ -2082,11 +2082,11 @@ fn display_value_terminator() { let expected = str![[r#" Likes seeing the value terminator -Usage: test --cmd ... +Usage: test --cmd ... ; Options: - --cmd ... command to run - -h, --help Print help + --cmd ... ; command to run [value terminator: ";"] + -h, --help Print help "#]]; utils::assert_output(cmd, "test --help", expected, false); @@ -2118,10 +2118,10 @@ fn custom_headers_headers() { let expected = str![[r#" does stuff -Usage: test [OPTIONS] --fake +Usage: test [OPTIONS] --fake : Options: - -f, --fake some help + -f, --fake : some help [value delimiter: ':'] -h, --help Print help -V, --version Print version @@ -2189,10 +2189,10 @@ fn multiple_custom_help_headers() { let expected = str![[r#" does stuff -Usage: test [OPTIONS] --fake --birthday-song --birthday-song-volume +Usage: test [OPTIONS] --fake : --birthday-song --birthday-song-volume Options: - -f, --fake some help + -f, --fake : some help [value delimiter: ':'] --style