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