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

fix(help): Ensure consistency in usage #4145

Merged
merged 1 commit into from Aug 29, 2022
Merged
Show file tree
Hide file tree
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
12 changes: 0 additions & 12 deletions src/builder/arg.rs
Expand Up @@ -3932,18 +3932,6 @@ impl Arg {
self.is_takes_value_set() || self.long.is_some() || self.short.is_none()
}

// Used for positionals when printing
pub(crate) fn multiple_str(&self) -> &str {
let mult_vals = self.val_names.len() > 1;
if (self.is_multiple_values_set() || matches!(*self.get_action(), ArgAction::Append))
&& !mult_vals
{
"..."
} else {
""
}
}

// Used for positionals when printing
pub(crate) fn name_no_brackets(&self) -> String {
debug!("Arg::name_no_brackets:{}", self.get_id());
Expand Down
19 changes: 6 additions & 13 deletions src/output/usage.rs
Expand Up @@ -104,15 +104,12 @@ impl<'cmd> Usage<'cmd> {
let req = pos.is_required_set();
if req && self.cmd.get_positionals().any(|p| !p.is_required_set()) {
styled.literal(" -- ");
styled.placeholder("<");
} else if req {
styled.placeholder(" [--] <");
styled.placeholder(" [--] ");
} else {
styled.placeholder(" [-- <");
styled.placeholder(" [-- ");
}
styled.placeholder(&*pos.name_no_brackets());
styled.placeholder('>');
styled.placeholder(pos.multiple_str());
styled.extend(pos.stylized(Some(true)).into_iter());
if !req {
styled.placeholder(']');
}
Expand Down Expand Up @@ -246,11 +243,7 @@ impl<'cmd> Usage<'cmd> {
pos.get_id()
);

Some(format!(
" [{}]{}",
pos.name_no_brackets(),
pos.multiple_str()
))
Some(format!(" {}", pos.stylized(Some(false))))
} else if self.cmd.is_dont_collapse_args_in_usage_set()
&& self.cmd.has_positionals()
&& incl_reqs
Expand All @@ -262,7 +255,7 @@ impl<'cmd> Usage<'cmd> {
.filter(|pos| !pos.is_required_set())
.filter(|pos| !pos.is_hide_set())
.filter(|pos| !pos.is_last_set())
.map(|pos| format!(" [{}]{}", pos.name_no_brackets(), pos.multiple_str()))
.map(|pos| format!(" {}", pos.stylized(Some(false))))
.collect::<Vec<_>>()
.join(""),
)
Expand All @@ -289,7 +282,7 @@ impl<'cmd> Usage<'cmd> {
.filter(|pos| !pos.is_required_set())
.filter(|pos| !pos.is_hide_set())
.filter(|pos| !pos.is_last_set())
.map(|pos| format!(" [{}]{}", pos.name_no_brackets(), pos.multiple_str()))
.map(|pos| format!(" {}", pos.stylized(Some(false))))
.collect::<Vec<_>>()
.join(""),
)
Expand Down