Skip to content

Commit

Permalink
Merge pull request #4145 from epage/optional
Browse files Browse the repository at this point in the history
fix(help): Ensure consistency in usage
  • Loading branch information
epage committed Aug 29, 2022
2 parents 567bff7 + 76dd3a1 commit 45d56ca
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 25 deletions.
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

0 comments on commit 45d56ca

Please sign in to comment.