diff --git a/clap_builder/src/builder/arg.rs b/clap_builder/src/builder/arg.rs index e3d0d7d0ef7..23c6a9bd0da 100644 --- a/clap_builder/src/builder/arg.rs +++ b/clap_builder/src/builder/arg.rs @@ -2645,7 +2645,7 @@ impl Arg { /// ``` /// /// If we were to run the above program with `$ CONNECT=super_secret connect --help` the - /// `[default: CONNECT=super_secret]` portion of the help text would be omitted. + /// `[env: CONNECT=super_secret]` portion of the help text would be omitted. #[cfg(feature = "env")] #[inline] #[must_use] @@ -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 fb203b0e59e..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 @@ -2064,6 +2064,34 @@ Options: utils::assert_output(cmd, "test --help", expected, false); } +#[test] +fn display_value_terminator() { + let cmd = Command::new("test") + .author("Jaffa") + .about("Likes seeing the value terminator") + .arg( + Arg::new("cmd") + .long("cmd") + .action(ArgAction::Append) + .help("command to run") + .required(true) + .num_args(1..) + .value_terminator(";"), + ); + + let expected = str![[r#" +Likes seeing the value terminator + +Usage: test --cmd ... ; + +Options: + --cmd ... ; command to run [value terminator: ";"] + -h, --help Print help + +"#]]; + utils::assert_output(cmd, "test --help", expected, false); +} + #[test] fn custom_headers_headers() { let cmd = Command::new("blorp") @@ -2090,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 @@ -2161,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