Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change rendering of visible aliases to be more prominent #5454

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
68 changes: 35 additions & 33 deletions clap_builder/src/output/help_template.rs
Expand Up @@ -554,15 +554,39 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> {
use std::fmt::Write as _;
let literal = &self.styles.get_literal();

if let Some(s) = arg.get_short() {
if
arg.get_short().is_none()
&& arg.get_visible_short_aliases().is_none()
&& arg.get_long().is_some()
{
self.writer.push_str(" ");
return;
}

let mut first = true;
for s in arg.get_short().iter().chain(arg.get_visible_short_aliases().iter().flatten()) {
if !first {
let _ = write!(
self.writer,
", ",
);
}
let _ = write!(
self.writer,
"{}-{s}{}",
literal.render(),
literal.render_reset()
);
} else if arg.get_long().is_some() {
self.writer.push_str(" ");
first = false;
}

if arg.get_long().is_some() {
if first {
// We've printed nothing so add some spacing for the long arg
self.writer.push_str(" ");
} else {
self.writer.push_str(", ");
}
}
}

Expand All @@ -572,16 +596,21 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> {
use std::fmt::Write as _;
let literal = &self.styles.get_literal();

if let Some(long) = arg.get_long() {
if arg.get_short().is_some() {
self.writer.push_str(", ");
let mut first = true;
for long in arg.get_long().iter().chain(arg.get_visible_aliases().iter().flatten()) {
if !first {
let _ = write!(
self.writer,
", ",
);
}
let _ = write!(
self.writer,
"{}--{long}{}",
literal.render(),
literal.render_reset()
);
first = false;
}
}

Expand Down Expand Up @@ -816,33 +845,6 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> {
spec_vals.push(format!("[default: {pvs}]"));
}

let als = a
.aliases
.iter()
.filter(|&als| als.1) // visible
.map(|als| als.0.as_str()) // name
.collect::<Vec<_>>()
.join(", ");
if !als.is_empty() {
debug!("HelpTemplate::spec_vals: Found aliases...{:?}", a.aliases);
spec_vals.push(format!("[aliases: {als}]"));
}

let als = a
.short_aliases
.iter()
.filter(|&als| als.1) // visible
.map(|&als| als.0.to_string()) // name
.collect::<Vec<_>>()
.join(", ");
if !als.is_empty() {
debug!(
"HelpTemplate::spec_vals: Found short aliases...{:?}",
a.short_aliases
);
spec_vals.push(format!("[short aliases: {als}]"));
}

if !a.is_hide_possible_values_set() && !self.use_long_pv(a) {
let possible_vals = a.get_possible_values();
if !possible_vals.is_empty() {
Expand Down