mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 06:44:16 +00:00
refactor: Use newer anstyle API
This commit is contained in:
parent
df19cbb5eb
commit
8bd63d2721
6 changed files with 56 additions and 258 deletions
|
@ -4329,14 +4329,9 @@ impl Arg {
|
|||
let mut styled = StyledStr::new();
|
||||
// Write the name such --long or -l
|
||||
if let Some(l) = self.get_long() {
|
||||
let _ = write!(
|
||||
styled,
|
||||
"{}--{l}{}",
|
||||
literal.render(),
|
||||
literal.render_reset()
|
||||
);
|
||||
let _ = write!(styled, "{literal}--{l}{literal:#}",);
|
||||
} else if let Some(s) = self.get_short() {
|
||||
let _ = write!(styled, "{}-{s}{}", literal.render(), literal.render_reset());
|
||||
let _ = write!(styled, "{literal}-{s}{literal:#}");
|
||||
}
|
||||
styled.push_styled(&self.stylize_arg_suffix(styles, required));
|
||||
styled
|
||||
|
@ -4364,32 +4359,17 @@ impl Arg {
|
|||
} else {
|
||||
(placeholder, " ")
|
||||
};
|
||||
let _ = write!(styled, "{}{start}{}", style.render(), style.render_reset());
|
||||
let _ = write!(styled, "{style}{start}{style:#}");
|
||||
}
|
||||
if self.is_takes_value_set() || self.is_positional() {
|
||||
let required = required.unwrap_or_else(|| self.is_required_set());
|
||||
let arg_val = self.render_arg_val(required);
|
||||
let _ = write!(
|
||||
styled,
|
||||
"{}{arg_val}{}",
|
||||
placeholder.render(),
|
||||
placeholder.render_reset()
|
||||
);
|
||||
let _ = write!(styled, "{placeholder}{arg_val}{placeholder:#}",);
|
||||
} else if matches!(*self.get_action(), ArgAction::Count) {
|
||||
let _ = write!(
|
||||
styled,
|
||||
"{}...{}",
|
||||
placeholder.render(),
|
||||
placeholder.render_reset()
|
||||
);
|
||||
let _ = write!(styled, "{placeholder}...{placeholder:#}",);
|
||||
}
|
||||
if need_closing_bracket {
|
||||
let _ = write!(
|
||||
styled,
|
||||
"{}]{}",
|
||||
placeholder.render(),
|
||||
placeholder.render_reset()
|
||||
);
|
||||
let _ = write!(styled, "{placeholder}]{placeholder:#}",);
|
||||
}
|
||||
|
||||
styled
|
||||
|
|
|
@ -108,12 +108,7 @@ impl ErrorFormatter for RichFormatter {
|
|||
styled.push_str("\n");
|
||||
}
|
||||
for suggestion in suggestions {
|
||||
let _ = write!(
|
||||
styled,
|
||||
"\n{TAB}{}tip:{} ",
|
||||
valid.render(),
|
||||
valid.render_reset()
|
||||
);
|
||||
let _ = write!(styled, "\n{TAB}{valid}tip:{valid:#} ",);
|
||||
styled.push_styled(suggestion);
|
||||
}
|
||||
}
|
||||
|
@ -132,7 +127,7 @@ impl ErrorFormatter for RichFormatter {
|
|||
fn start_error(styled: &mut StyledStr, styles: &Styles) {
|
||||
use std::fmt::Write as _;
|
||||
let error = &styles.get_error();
|
||||
let _ = write!(styled, "{}error:{} ", error.render(), error.render_reset());
|
||||
let _ = write!(styled, "{error}error:{error:#} ");
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
|
@ -155,16 +150,12 @@ fn write_dynamic_context(
|
|||
prior_arg = None;
|
||||
let _ = write!(
|
||||
styled,
|
||||
"the argument '{}{invalid_arg}{}' cannot be used multiple times",
|
||||
invalid.render(),
|
||||
invalid.render_reset()
|
||||
"the argument '{invalid}{invalid_arg}{invalid:#}' cannot be used multiple times",
|
||||
);
|
||||
} else {
|
||||
let _ = write!(
|
||||
styled,
|
||||
"the argument '{}{invalid_arg}{}' cannot be used with",
|
||||
invalid.render(),
|
||||
invalid.render_reset()
|
||||
"the argument '{invalid}{invalid_arg}{invalid:#}' cannot be used with",
|
||||
);
|
||||
}
|
||||
} else if let Some(ContextValue::String(invalid_arg)) =
|
||||
|
@ -172,9 +163,7 @@ fn write_dynamic_context(
|
|||
{
|
||||
let _ = write!(
|
||||
styled,
|
||||
"the subcommand '{}{invalid_arg}{}' cannot be used with",
|
||||
invalid.render(),
|
||||
invalid.render_reset()
|
||||
"the subcommand '{invalid}{invalid_arg}{invalid:#}' cannot be used with",
|
||||
);
|
||||
} else {
|
||||
styled.push_str(error.kind().as_str().unwrap());
|
||||
|
@ -185,21 +174,11 @@ fn write_dynamic_context(
|
|||
ContextValue::Strings(values) => {
|
||||
styled.push_str(":");
|
||||
for v in values {
|
||||
let _ = write!(
|
||||
styled,
|
||||
"\n{TAB}{}{v}{}",
|
||||
invalid.render(),
|
||||
invalid.render_reset()
|
||||
);
|
||||
let _ = write!(styled, "\n{TAB}{invalid}{v}{invalid:#}",);
|
||||
}
|
||||
}
|
||||
ContextValue::String(value) => {
|
||||
let _ = write!(
|
||||
styled,
|
||||
" '{}{value}{}'",
|
||||
invalid.render(),
|
||||
invalid.render_reset()
|
||||
);
|
||||
let _ = write!(styled, " '{invalid}{value}{invalid:#}'",);
|
||||
}
|
||||
_ => {
|
||||
styled.push_str(" one or more of the other specified arguments");
|
||||
|
@ -214,9 +193,7 @@ fn write_dynamic_context(
|
|||
if let Some(ContextValue::String(invalid_arg)) = invalid_arg {
|
||||
let _ = write!(
|
||||
styled,
|
||||
"equal sign is needed when assigning values to '{}{invalid_arg}{}'",
|
||||
invalid.render(),
|
||||
invalid.render_reset()
|
||||
"equal sign is needed when assigning values to '{invalid}{invalid_arg}{invalid:#}'",
|
||||
);
|
||||
true
|
||||
} else {
|
||||
|
@ -234,18 +211,12 @@ fn write_dynamic_context(
|
|||
if invalid_value.is_empty() {
|
||||
let _ = write!(
|
||||
styled,
|
||||
"a value is required for '{}{invalid_arg}{}' but none was supplied",
|
||||
invalid.render(),
|
||||
invalid.render_reset()
|
||||
"a value is required for '{invalid}{invalid_arg}{invalid:#}' but none was supplied",
|
||||
);
|
||||
} else {
|
||||
let _ = write!(
|
||||
styled,
|
||||
"invalid value '{}{invalid_value}{}' for '{}{invalid_arg}{}'",
|
||||
invalid.render(),
|
||||
invalid.render_reset(),
|
||||
literal.render(),
|
||||
literal.render_reset()
|
||||
"invalid value '{invalid}{invalid_value}{invalid:#}' for '{literal}{invalid_arg}{literal:#}'",
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -262,9 +233,7 @@ fn write_dynamic_context(
|
|||
if let Some(ContextValue::String(invalid_sub)) = invalid_sub {
|
||||
let _ = write!(
|
||||
styled,
|
||||
"unrecognized subcommand '{}{invalid_sub}{}'",
|
||||
invalid.render(),
|
||||
invalid.render_reset()
|
||||
"unrecognized subcommand '{invalid}{invalid_sub}{invalid:#}'",
|
||||
);
|
||||
true
|
||||
} else {
|
||||
|
@ -276,12 +245,7 @@ fn write_dynamic_context(
|
|||
if let Some(ContextValue::Strings(invalid_arg)) = invalid_arg {
|
||||
styled.push_str("the following required arguments were not provided:");
|
||||
for v in invalid_arg {
|
||||
let _ = write!(
|
||||
styled,
|
||||
"\n{TAB}{}{v}{}",
|
||||
valid.render(),
|
||||
valid.render_reset()
|
||||
);
|
||||
let _ = write!(styled, "\n{TAB}{valid}{v}{valid:#}",);
|
||||
}
|
||||
true
|
||||
} else {
|
||||
|
@ -293,9 +257,7 @@ fn write_dynamic_context(
|
|||
if let Some(ContextValue::String(invalid_sub)) = invalid_sub {
|
||||
let _ = write!(
|
||||
styled,
|
||||
"'{}{invalid_sub}{}' requires a subcommand but one was not provided",
|
||||
invalid.render(),
|
||||
invalid.render_reset()
|
||||
"'{invalid}{invalid_sub}{invalid:#}' requires a subcommand but one was not provided",
|
||||
);
|
||||
let values = error.get(ContextKind::ValidSubcommand);
|
||||
write_values_list("subcommands", styled, valid, values);
|
||||
|
@ -316,11 +278,7 @@ fn write_dynamic_context(
|
|||
{
|
||||
let _ = write!(
|
||||
styled,
|
||||
"unexpected value '{}{invalid_value}{}' for '{}{invalid_arg}{}' found; no more were expected",
|
||||
invalid.render(),
|
||||
invalid.render_reset(),
|
||||
literal.render(),
|
||||
literal.render_reset(),
|
||||
"unexpected value '{invalid}{invalid_value}{invalid:#}' for '{literal}{invalid_arg}{literal:#}' found; no more were expected",
|
||||
);
|
||||
true
|
||||
} else {
|
||||
|
@ -340,13 +298,7 @@ fn write_dynamic_context(
|
|||
let were_provided = singular_or_plural(*actual_num_values as usize);
|
||||
let _ = write!(
|
||||
styled,
|
||||
"{}{min_values}{} values required by '{}{invalid_arg}{}'; only {}{actual_num_values}{}{were_provided}",
|
||||
valid.render(),
|
||||
valid.render_reset(),
|
||||
literal.render(),
|
||||
literal.render_reset(),
|
||||
invalid.render(),
|
||||
invalid.render_reset(),
|
||||
"{valid}{min_values}{valid:#} values required by '{literal}{invalid_arg}{literal:#}'; only {invalid}{actual_num_values}{invalid:#}{were_provided}",
|
||||
);
|
||||
true
|
||||
} else {
|
||||
|
@ -363,11 +315,7 @@ fn write_dynamic_context(
|
|||
{
|
||||
let _ = write!(
|
||||
styled,
|
||||
"invalid value '{}{invalid_value}{}' for '{}{invalid_arg}{}'",
|
||||
invalid.render(),
|
||||
invalid.render_reset(),
|
||||
literal.render(),
|
||||
literal.render_reset(),
|
||||
"invalid value '{invalid}{invalid_value}{invalid:#}' for '{literal}{invalid_arg}{literal:#}'",
|
||||
);
|
||||
if let Some(source) = error.inner.source.as_deref() {
|
||||
let _ = write!(styled, ": {source}");
|
||||
|
@ -390,13 +338,7 @@ fn write_dynamic_context(
|
|||
let were_provided = singular_or_plural(*actual_num_values as usize);
|
||||
let _ = write!(
|
||||
styled,
|
||||
"{}{num_values}{} values required for '{}{invalid_arg}{}' but {}{actual_num_values}{}{were_provided}",
|
||||
valid.render(),
|
||||
valid.render_reset(),
|
||||
literal.render(),
|
||||
literal.render_reset(),
|
||||
invalid.render(),
|
||||
invalid.render_reset(),
|
||||
"{valid}{num_values}{valid:#} values required for '{literal}{invalid_arg}{literal:#}' but {invalid}{actual_num_values}{invalid:#}{were_provided}",
|
||||
);
|
||||
true
|
||||
} else {
|
||||
|
@ -408,9 +350,7 @@ fn write_dynamic_context(
|
|||
if let Some(ContextValue::String(invalid_arg)) = invalid_arg {
|
||||
let _ = write!(
|
||||
styled,
|
||||
"unexpected argument '{}{invalid_arg}{}' found",
|
||||
invalid.render(),
|
||||
invalid.render_reset(),
|
||||
"unexpected argument '{invalid}{invalid_arg}{invalid:#}' found",
|
||||
);
|
||||
true
|
||||
} else {
|
||||
|
@ -437,13 +377,11 @@ fn write_values_list(
|
|||
if !possible_values.is_empty() {
|
||||
let _ = write!(styled, "\n{TAB}[{list_name}: ");
|
||||
|
||||
let style = valid.render();
|
||||
let reset = valid.render_reset();
|
||||
for (idx, val) in possible_values.iter().enumerate() {
|
||||
if idx > 0 {
|
||||
styled.push_str(", ");
|
||||
}
|
||||
let _ = write!(styled, "{style}{}{reset}", Escape(val));
|
||||
let _ = write!(styled, "{valid}{}{valid:#}", Escape(val));
|
||||
}
|
||||
|
||||
styled.push_str("]");
|
||||
|
@ -517,9 +455,7 @@ fn try_help(styled: &mut StyledStr, styles: &Styles, help: Option<&str>) {
|
|||
let literal = &styles.get_literal();
|
||||
let _ = write!(
|
||||
styled,
|
||||
"\n\nFor more information, try '{}{help}{}'.\n",
|
||||
literal.render(),
|
||||
literal.render_reset()
|
||||
"\n\nFor more information, try '{literal}{help}{literal:#}'.\n",
|
||||
);
|
||||
} else {
|
||||
styled.push_str("\n");
|
||||
|
@ -530,18 +466,12 @@ fn try_help(styled: &mut StyledStr, styles: &Styles, help: Option<&str>) {
|
|||
fn did_you_mean(styled: &mut StyledStr, styles: &Styles, context: &str, possibles: &ContextValue) {
|
||||
use std::fmt::Write as _;
|
||||
|
||||
let _ = write!(
|
||||
styled,
|
||||
"{TAB}{}tip:{}",
|
||||
styles.get_valid().render(),
|
||||
styles.get_valid().render_reset()
|
||||
);
|
||||
let valid = &styles.get_valid();
|
||||
let _ = write!(styled, "{TAB}{valid}tip:{valid:#}",);
|
||||
if let ContextValue::String(possible) = possibles {
|
||||
let _ = write!(
|
||||
styled,
|
||||
" a similar {context} exists: '{}{possible}{}'",
|
||||
styles.get_valid().render(),
|
||||
styles.get_valid().render_reset()
|
||||
" a similar {context} exists: '{valid}{possible}{valid:#}'",
|
||||
);
|
||||
} else if let ContextValue::Strings(possibles) = possibles {
|
||||
if possibles.len() == 1 {
|
||||
|
@ -553,12 +483,7 @@ fn did_you_mean(styled: &mut StyledStr, styles: &Styles, context: &str, possible
|
|||
if i != 0 {
|
||||
styled.push_str(", ");
|
||||
}
|
||||
let _ = write!(
|
||||
styled,
|
||||
"'{}{possible}{}'",
|
||||
styles.get_valid().render(),
|
||||
styles.get_valid().render_reset()
|
||||
);
|
||||
let _ = write!(styled, "'{valid}{possible}{valid:#}'",);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -490,11 +490,7 @@ impl<F: ErrorFormatter> Error<F> {
|
|||
let mut styled_suggestion = StyledStr::new();
|
||||
let _ = write!(
|
||||
styled_suggestion,
|
||||
"to pass '{}{subcmd}{}' as a value, use '{}{name} -- {subcmd}{}'",
|
||||
invalid.render(),
|
||||
invalid.render_reset(),
|
||||
valid.render(),
|
||||
valid.render_reset()
|
||||
"to pass '{invalid}{subcmd}{invalid:#}' as a value, use '{valid}{name} -- {subcmd}{valid:#}'",
|
||||
);
|
||||
suggestions.push(styled_suggestion);
|
||||
}
|
||||
|
@ -726,11 +722,7 @@ impl<F: ErrorFormatter> Error<F> {
|
|||
let mut styled_suggestion = StyledStr::new();
|
||||
let _ = write!(
|
||||
styled_suggestion,
|
||||
"to pass '{}{arg}{}' as a value, use '{}-- {arg}{}'",
|
||||
invalid.render(),
|
||||
invalid.render_reset(),
|
||||
valid.render(),
|
||||
valid.render_reset()
|
||||
"to pass '{invalid}{arg}{invalid:#}' as a value, use '{valid}-- {arg}{valid:#}'",
|
||||
);
|
||||
suggestions.push(styled_suggestion);
|
||||
}
|
||||
|
@ -744,12 +736,7 @@ impl<F: ErrorFormatter> Error<F> {
|
|||
match did_you_mean {
|
||||
Some((flag, Some(sub))) => {
|
||||
let mut styled_suggestion = StyledStr::new();
|
||||
let _ = write!(
|
||||
styled_suggestion,
|
||||
"'{}{sub} {flag}{}' exists",
|
||||
valid.render(),
|
||||
valid.render_reset()
|
||||
);
|
||||
let _ = write!(styled_suggestion, "'{valid}{sub} {flag}{valid:#}' exists",);
|
||||
suggestions.push(styled_suggestion);
|
||||
}
|
||||
Some((flag, None)) => {
|
||||
|
@ -787,11 +774,7 @@ impl<F: ErrorFormatter> Error<F> {
|
|||
let mut styled_suggestion = StyledStr::new();
|
||||
let _ = write!(
|
||||
styled_suggestion,
|
||||
"subcommand '{}{arg}{}' exists; to use it, remove the '{}--{}' before it",
|
||||
valid.render(),
|
||||
valid.render_reset(),
|
||||
invalid.render(),
|
||||
invalid.render_reset()
|
||||
"subcommand '{valid}{arg}{valid:#}' exists; to use it, remove the '{invalid}--{invalid:#}' before it",
|
||||
);
|
||||
|
||||
err = err.extend_context_unchecked([
|
||||
|
|
|
@ -540,7 +540,7 @@ macro_rules! debug {
|
|||
let module_path = module_path!();
|
||||
let body = format!($($arg)*);
|
||||
let mut styled = $crate::builder::StyledStr::new();
|
||||
let _ = write!(styled, "{}[{module_path:>28}]{body}{}\n", hint.render(), hint.render_reset());
|
||||
let _ = write!(styled, "{hint}[{module_path:>28}]{body}{hint:#}\n");
|
||||
let color = $crate::output::fmt::Colorizer::new($crate::output::fmt::Stream::Stderr, $crate::ColorChoice::Auto).with_content(styled);
|
||||
let _ = color.print();
|
||||
})
|
||||
|
|
|
@ -406,12 +406,7 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> {
|
|||
.cmd
|
||||
.get_subcommand_help_heading()
|
||||
.unwrap_or(&default_help_heading);
|
||||
let _ = write!(
|
||||
self.writer,
|
||||
"{}{help_heading}:{}\n",
|
||||
header.render(),
|
||||
header.render_reset()
|
||||
);
|
||||
let _ = write!(self.writer, "{header}{help_heading}:{header:#}\n",);
|
||||
|
||||
self.write_subcommands(self.cmd);
|
||||
}
|
||||
|
@ -423,12 +418,7 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> {
|
|||
first = false;
|
||||
// Write positional args if any
|
||||
let help_heading = "Arguments";
|
||||
let _ = write!(
|
||||
self.writer,
|
||||
"{}{help_heading}:{}\n",
|
||||
header.render(),
|
||||
header.render_reset()
|
||||
);
|
||||
let _ = write!(self.writer, "{header}{help_heading}:{header:#}\n",);
|
||||
self.write_args(&pos, "Arguments", positional_sort_key);
|
||||
}
|
||||
|
||||
|
@ -438,12 +428,7 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> {
|
|||
}
|
||||
first = false;
|
||||
let help_heading = "Options";
|
||||
let _ = write!(
|
||||
self.writer,
|
||||
"{}{help_heading}:{}\n",
|
||||
header.render(),
|
||||
header.render_reset()
|
||||
);
|
||||
let _ = write!(self.writer, "{header}{help_heading}:{header:#}\n",);
|
||||
self.write_args(&non_pos, "Options", option_sort_key);
|
||||
}
|
||||
if !custom_headings.is_empty() {
|
||||
|
@ -465,12 +450,7 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> {
|
|||
self.writer.push_str("\n\n");
|
||||
}
|
||||
first = false;
|
||||
let _ = write!(
|
||||
self.writer,
|
||||
"{}{heading}:{}\n",
|
||||
header.render(),
|
||||
header.render_reset()
|
||||
);
|
||||
let _ = write!(self.writer, "{header}{heading}:{header:#}\n",);
|
||||
self.write_args(&args, heading, option_sort_key);
|
||||
}
|
||||
}
|
||||
|
@ -554,12 +534,7 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> {
|
|||
let literal = &self.styles.get_literal();
|
||||
|
||||
if let Some(s) = arg.get_short() {
|
||||
let _ = write!(
|
||||
self.writer,
|
||||
"{}-{s}{}",
|
||||
literal.render(),
|
||||
literal.render_reset()
|
||||
);
|
||||
let _ = write!(self.writer, "{literal}-{s}{literal:#}",);
|
||||
} else if arg.get_long().is_some() {
|
||||
self.writer.push_str(" ");
|
||||
}
|
||||
|
@ -575,12 +550,7 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> {
|
|||
if arg.get_short().is_some() {
|
||||
self.writer.push_str(", ");
|
||||
}
|
||||
let _ = write!(
|
||||
self.writer,
|
||||
"{}--{long}{}",
|
||||
literal.render(),
|
||||
literal.render_reset()
|
||||
);
|
||||
let _ = write!(self.writer, "{literal}--{long}{literal:#}",);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -707,12 +677,7 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> {
|
|||
let name = pv.get_name();
|
||||
|
||||
let mut descr = StyledStr::new();
|
||||
let _ = write!(
|
||||
&mut descr,
|
||||
"{}{name}{}",
|
||||
literal.render(),
|
||||
literal.render_reset()
|
||||
);
|
||||
let _ = write!(&mut descr, "{literal}{name}{literal:#}",);
|
||||
if let Some(help) = pv.get_help() {
|
||||
debug!("HelpTemplate::help: Possible Value help");
|
||||
// To align help messages
|
||||
|
@ -917,12 +882,7 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> {
|
|||
.or_else(|| subcommand.get_long_about())
|
||||
.unwrap_or_default();
|
||||
|
||||
let _ = write!(
|
||||
self.writer,
|
||||
"{}{heading}:{}\n",
|
||||
header.render(),
|
||||
header.render_reset()
|
||||
);
|
||||
let _ = write!(self.writer, "{header}{heading}:{header:#}\n",);
|
||||
if !about.is_empty() {
|
||||
let _ = write!(self.writer, "{about}\n",);
|
||||
}
|
||||
|
@ -962,27 +922,12 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> {
|
|||
{
|
||||
let mut styled = StyledStr::new();
|
||||
let name = subcommand.get_name();
|
||||
let _ = write!(
|
||||
styled,
|
||||
"{}{name}{}",
|
||||
literal.render(),
|
||||
literal.render_reset()
|
||||
);
|
||||
let _ = write!(styled, "{literal}{name}{literal:#}",);
|
||||
if let Some(short) = subcommand.get_short_flag() {
|
||||
let _ = write!(
|
||||
styled,
|
||||
", {}-{short}{}",
|
||||
literal.render(),
|
||||
literal.render_reset()
|
||||
);
|
||||
let _ = write!(styled, ", {literal}-{short}{literal:#}",);
|
||||
}
|
||||
if let Some(long) = subcommand.get_long_flag() {
|
||||
let _ = write!(
|
||||
styled,
|
||||
", {}--{long}{}",
|
||||
literal.render(),
|
||||
literal.render_reset()
|
||||
);
|
||||
let _ = write!(styled, ", {literal}--{long}{literal:#}",);
|
||||
}
|
||||
longest = longest.max(styled.display_width());
|
||||
ord_v.push((subcommand.get_display_order(), styled, subcommand));
|
||||
|
|
|
@ -144,12 +144,7 @@ impl<'cmd> Usage<'cmd> {
|
|||
.cmd
|
||||
.get_subcommand_value_name()
|
||||
.unwrap_or(DEFAULT_SUB_VALUE_NAME);
|
||||
let _ = write!(
|
||||
styled,
|
||||
"{}<{value_name}>{}",
|
||||
placeholder.render(),
|
||||
placeholder.render_reset()
|
||||
);
|
||||
let _ = write!(styled, "{placeholder}<{value_name}>{placeholder:#}",);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -162,21 +157,11 @@ impl<'cmd> Usage<'cmd> {
|
|||
let bin_name = self.cmd.get_usage_name_fallback();
|
||||
if !bin_name.is_empty() {
|
||||
// the trim won't properly remove a leading space due to the formatting
|
||||
let _ = write!(
|
||||
styled,
|
||||
"{}{bin_name}{} ",
|
||||
literal.render(),
|
||||
literal.render_reset()
|
||||
);
|
||||
let _ = write!(styled, "{literal}{bin_name}{literal:#} ",);
|
||||
}
|
||||
|
||||
if used.is_empty() && self.needs_options_tag() {
|
||||
let _ = write!(
|
||||
styled,
|
||||
"{}[OPTIONS]{} ",
|
||||
placeholder.render(),
|
||||
placeholder.render_reset()
|
||||
);
|
||||
let _ = write!(styled, "{placeholder}[OPTIONS]{placeholder:#} ",);
|
||||
}
|
||||
|
||||
self.write_args(styled, used, !incl_reqs);
|
||||
|
@ -202,35 +187,15 @@ impl<'cmd> Usage<'cmd> {
|
|||
if self.cmd.is_args_conflicts_with_subcommands_set() {
|
||||
let bin_name = self.cmd.get_usage_name_fallback();
|
||||
// Short-circuit full usage creation since no args will be relevant
|
||||
let _ = write!(
|
||||
styled,
|
||||
"{}{bin_name}{} ",
|
||||
literal.render(),
|
||||
literal.render_reset()
|
||||
);
|
||||
let _ = write!(styled, "{literal}{bin_name}{literal:#} ",);
|
||||
} else {
|
||||
self.write_arg_usage(styled, &[], false);
|
||||
}
|
||||
let _ = write!(
|
||||
styled,
|
||||
"{}<{value_name}>{}",
|
||||
placeholder.render(),
|
||||
placeholder.render_reset()
|
||||
);
|
||||
let _ = write!(styled, "{placeholder}<{value_name}>{placeholder:#}",);
|
||||
} else if self.cmd.is_subcommand_required_set() {
|
||||
let _ = write!(
|
||||
styled,
|
||||
"{}<{value_name}>{}",
|
||||
placeholder.render(),
|
||||
placeholder.render_reset()
|
||||
);
|
||||
let _ = write!(styled, "{placeholder}<{value_name}>{placeholder:#}",);
|
||||
} else {
|
||||
let _ = write!(
|
||||
styled,
|
||||
"{}[{value_name}]{}",
|
||||
placeholder.render(),
|
||||
placeholder.render_reset()
|
||||
);
|
||||
let _ = write!(styled, "{placeholder}[{value_name}]{placeholder:#}",);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -373,7 +338,7 @@ impl<'cmd> Usage<'cmd> {
|
|||
if pos.is_last_set() {
|
||||
let styled = required_positionals[index].take().unwrap();
|
||||
let mut new = StyledStr::new();
|
||||
let _ = write!(new, "{}--{} ", literal.render(), literal.render_reset());
|
||||
let _ = write!(new, "{literal}--{literal:#} ");
|
||||
new.push_styled(&styled);
|
||||
required_positionals[index] = Some(new);
|
||||
}
|
||||
|
@ -381,9 +346,9 @@ impl<'cmd> Usage<'cmd> {
|
|||
let mut styled;
|
||||
if pos.is_last_set() {
|
||||
styled = StyledStr::new();
|
||||
let _ = write!(styled, "{}[--{} ", literal.render(), literal.render_reset());
|
||||
let _ = write!(styled, "{literal}[--{literal:#} ");
|
||||
styled.push_styled(&pos.stylized(self.styles, Some(true)));
|
||||
let _ = write!(styled, "{}]{}", literal.render(), literal.render_reset());
|
||||
let _ = write!(styled, "{literal}]{literal:#}");
|
||||
} else {
|
||||
styled = pos.stylized(self.styles, Some(false));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue