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

chore: Inline simple non-mixed format args #4890

Merged
merged 1 commit into from
May 4, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clap_builder/src/builder/arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4107,7 +4107,7 @@ impl Arg {
/// let value_parser = cmd.get_arguments()
/// .find(|a| a.get_id() == "port").unwrap()
/// .get_value_parser();
/// println!("{:?}", value_parser);
/// println!("{value_parser:?}");
/// ```
pub fn get_value_parser(&self) -> &super::ValueParser {
if let Some(value_parser) = self.value_parser.as_ref() {
Expand Down
21 changes: 9 additions & 12 deletions clap_builder/src/builder/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,10 +684,7 @@ impl Command {
if let Some(command) = argv0.file_stem().and_then(|f| f.to_str()) {
// Stop borrowing command so we can get another mut ref to it.
let command = command.to_owned();
debug!(
"Command::try_get_matches_from_mut: Parsed command {} from argv",
command
);
debug!("Command::try_get_matches_from_mut: Parsed command {command} from argv");

debug!("Command::try_get_matches_from_mut: Reinserting command into arguments so subcommand parser matches it");
raw_args.insert(&cursor, [&command]);
Expand Down Expand Up @@ -789,7 +786,7 @@ impl Command {
/// let mut cmd = Command::new("myprog");
/// let mut out = io::stdout();
/// let help = cmd.render_help();
/// println!("{}", help);
/// println!("{help}");
/// ```
/// [`io::Write`]: std::io::Write
/// [`-h` (short)]: Arg::help()
Expand All @@ -816,7 +813,7 @@ impl Command {
/// let mut cmd = Command::new("myprog");
/// let mut out = io::stdout();
/// let help = cmd.render_long_help();
/// println!("{}", help);
/// println!("{help}");
/// ```
/// [`io::Write`]: std::io::Write
/// [`-h` (short)]: Arg::help()
Expand Down Expand Up @@ -984,7 +981,7 @@ impl Command {
///
/// let r = cmd.try_get_matches_from(vec!["cmd", "-c", "file", "-f", "-x"]);
///
/// assert!(r.is_ok(), "unexpected error: {:?}", r);
/// assert!(r.is_ok(), "unexpected error: {r:?}");
/// let m = r.unwrap();
/// assert_eq!(m.get_one::<String>("config").unwrap(), "file");
/// assert!(m.get_flag("f"));
Expand Down Expand Up @@ -3695,7 +3692,7 @@ impl Command {
/// let cmd = clap::Command::new("raw")
/// .external_subcommand_value_parser(clap::value_parser!(String));
/// let value_parser = cmd.get_external_subcommand_value_parser();
/// println!("{:?}", value_parser);
/// println!("{value_parser:?}");
/// ```
pub fn get_external_subcommand_value_parser(&self) -> Option<&super::ValueParser> {
if !self.is_allow_external_subcommands_set() {
Expand Down Expand Up @@ -3792,7 +3789,7 @@ impl Command {
let mut parser = Parser::new(self);
if let Err(error) = parser.get_matches_with(&mut matcher, raw_args, args_cursor) {
if self.is_set(AppSettings::IgnoreErrors) {
debug!("Command::_do_parse: ignoring error: {}", error);
debug!("Command::_do_parse: ignoring error: {error}");
} else {
return Err(error);
}
Expand Down Expand Up @@ -4436,7 +4433,7 @@ impl Command {

/// Iterate through the groups this arg is member of.
pub(crate) fn groups_for_arg<'a>(&'a self, arg: &Id) -> impl Iterator<Item = Id> + 'a {
debug!("Command::groups_for_arg: id={:?}", arg);
debug!("Command::groups_for_arg: id={arg:?}");
let arg = arg.clone();
self.groups
.iter()
Expand Down Expand Up @@ -4476,7 +4473,7 @@ impl Command {
}

pub(crate) fn unroll_args_in_group(&self, group: &Id) -> Vec<Id> {
debug!("Command::unroll_args_in_group: group={:?}", group);
debug!("Command::unroll_args_in_group: group={group:?}");
let mut g_vec = vec![group];
let mut args = vec![];

Expand All @@ -4489,7 +4486,7 @@ impl Command {
.args
.iter()
{
debug!("Command::unroll_args_in_group:iter: entity={:?}", n);
debug!("Command::unroll_args_in_group:iter: entity={n:?}");
if !args.contains(n) {
if self.find(n).is_some() {
debug!("Command::unroll_args_in_group:iter: this is an arg");
Expand Down
2 changes: 1 addition & 1 deletion clap_builder/src/builder/debug_asserts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ fn assert_app_flags(cmd: &Command) {
)+

if !s.is_empty() {
panic!("{}", s)
panic!("{s}")
}
}
};
Expand Down
8 changes: 4 additions & 4 deletions clap_builder/src/builder/value_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2382,17 +2382,17 @@ pub mod via_prelude {
/// # use clap::ColorChoice;
/// // Built-in types
/// let parser = clap::value_parser!(String);
/// assert_eq!(format!("{:?}", parser), "ValueParser::string");
/// assert_eq!(format!("{parser:?}"), "ValueParser::string");
/// let parser = clap::value_parser!(std::ffi::OsString);
/// assert_eq!(format!("{:?}", parser), "ValueParser::os_string");
/// assert_eq!(format!("{parser:?}"), "ValueParser::os_string");
/// let parser = clap::value_parser!(std::path::PathBuf);
/// assert_eq!(format!("{:?}", parser), "ValueParser::path_buf");
/// assert_eq!(format!("{parser:?}"), "ValueParser::path_buf");
/// clap::value_parser!(u16).range(3000..);
/// clap::value_parser!(u64).range(3000..);
///
/// // FromStr types
/// let parser = clap::value_parser!(usize);
/// assert_eq!(format!("{:?}", parser), "_AnonymousValueParser(ValueParser::other(usize))");
/// assert_eq!(format!("{parser:?}"), "_AnonymousValueParser(ValueParser::other(usize))");
///
/// // ValueEnum types
/// clap::value_parser!(ColorChoice);
Expand Down
2 changes: 1 addition & 1 deletion clap_builder/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ impl<F: ErrorFormatter> Error<F> {
/// },
/// Err(err) => {
/// let err = err.render();
/// println!("{}", err);
/// println!("{err}");
/// // do_something
/// },
/// };
Expand Down
5 changes: 2 additions & 3 deletions clap_builder/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ macro_rules! arg_impl {
debug_assert_eq!(
ident_or_char_literal.len(),
1,
"Single-letter identifier expected, got {}",
ident_or_char_literal
"Single-letter identifier expected, got {ident_or_char_literal}",
);
ident_or_char_literal.chars().next().unwrap()
}};
Expand Down Expand Up @@ -404,7 +403,7 @@ macro_rules! arg_impl {
$arg.action($crate::ArgAction::Count)
}
action => {
panic!("Unexpected action {:?}", action)
panic!("Unexpected action {action:?}")
}
};
let arg = $crate::arg_impl! {
Expand Down
25 changes: 9 additions & 16 deletions clap_builder/src/output/help_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,10 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> {
}
}
}

/// Sorts arguments by length and display order and write their help to the wrapped stream.
fn write_args(&mut self, args: &[&Arg], _category: &str, sort_key: ArgSortKey) {
debug!("HelpTemplate::write_args {}", _category);
debug!("HelpTemplate::write_args {_category}");
// The shortest an arg can legally be is 2 (i.e. '-x')
let mut longest = 2;
let mut ord_v = Vec::new();
Expand Down Expand Up @@ -577,8 +578,7 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> {
};
let spcs = longest + padding - self_len;
debug!(
"HelpTemplate::align_to_about: positional=false arg_len={}, spaces={}",
self_len, spcs
"HelpTemplate::align_to_about: positional=false arg_len={self_len}, spaces={spcs}"
);

spcs
Expand All @@ -587,8 +587,7 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> {
let padding = TAB_WIDTH;
let spcs = longest + padding - self_len;
debug!(
"HelpTemplate::align_to_about: positional=true arg_len={}, spaces={}",
self_len, spcs
"HelpTemplate::align_to_about: positional=true arg_len={self_len}, spaces={spcs}",
);

spcs
Expand All @@ -612,7 +611,7 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> {

// Is help on next line, if so then indent
if next_line_help {
debug!("HelpTemplate::help: Next Line...{:?}", next_line_help);
debug!("HelpTemplate::help: Next Line...{next_line_help:?}");
self.writer.push_str("\n");
self.writer.push_str(TAB);
self.writer.push_str(NEXT_LINE_INDENT);
Expand Down Expand Up @@ -659,10 +658,7 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> {
&& !arg.is_hide_possible_values_set()
&& self.use_long_pv(arg)
{
debug!(
"HelpTemplate::help: Found possible vals...{:?}",
possible_vals
);
debug!("HelpTemplate::help: Found possible vals...{possible_vals:?}");
let longest = possible_vals
.iter()
.filter(|f| !f.is_hide_set())
Expand Down Expand Up @@ -741,7 +737,7 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> {
}

fn spec_vals(&self, a: &Arg) -> String {
debug!("HelpTemplate::spec_vals: a={}", a);
debug!("HelpTemplate::spec_vals: a={a}");
let mut spec_vals = Vec::new();
#[cfg(feature = "env")]
if let Some(ref env) = a.env {
Expand Down Expand Up @@ -817,10 +813,7 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> {

let possible_vals = a.get_possible_values();
if !possible_vals.is_empty() && !a.is_hide_possible_values_set() && !self.use_long_pv(a) {
debug!(
"HelpTemplate::spec_vals: Found possible vals...{:?}",
possible_vals
);
debug!("HelpTemplate::spec_vals: Found possible vals...{possible_vals:?}");

let pvs = possible_vals
.iter()
Expand Down Expand Up @@ -896,7 +889,7 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> {
}
ord_v.sort_by(|a, b| (a.0, &a.1).cmp(&(b.0, &b.1)));

debug!("HelpTemplate::write_subcommands longest = {}", longest);
debug!("HelpTemplate::write_subcommands longest = {longest}");

let next_line_help = self.will_subcommands_wrap(cmd.get_subcommands(), longest);

Expand Down
4 changes: 2 additions & 2 deletions clap_builder/src/output/textwrap/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ mod tests {
let desc = format!("{:?} U+{:04X}", ch, ch as u32);

#[cfg(feature = "unicode")]
assert_eq!(ch.width().unwrap(), 1, "char: {}", desc);
assert_eq!(ch.width().unwrap(), 1, "char: {desc}");

#[cfg(not(feature = "unicode"))]
assert_eq!(ch_width(ch), 1, "char: {desc}");
Expand All @@ -120,7 +120,7 @@ mod tests {
let desc = format!("{:?} U+{:04X}", ch, ch as u32);

#[cfg(feature = "unicode")]
assert!(ch.width().unwrap() <= 2, "char: {}", desc);
assert!(ch.width().unwrap() <= 2, "char: {desc}");

#[cfg(not(feature = "unicode"))]
assert_eq!(ch_width(ch), 1, "char: {desc}");
Expand Down
29 changes: 10 additions & 19 deletions clap_builder/src/output/usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl<'cmd> Usage<'cmd> {
impl<'cmd> Usage<'cmd> {
// Creates a usage string for display in help messages (i.e. not for errors)
fn create_help_usage(&self, incl_reqs: bool) -> StyledStr {
debug!("Usage::create_help_usage; incl_reqs={:?}", incl_reqs);
debug!("Usage::create_help_usage; incl_reqs={incl_reqs:?}");
use std::fmt::Write as _;
let literal = &self.styles.get_literal();
let placeholder = &self.styles.get_placeholder();
Expand Down Expand Up @@ -157,7 +157,7 @@ impl<'cmd> Usage<'cmd> {
}
}
styled.trim();
debug!("Usage::create_help_usage: usage={}", styled);
debug!("Usage::create_help_usage: usage={styled}");
styled
}

Expand Down Expand Up @@ -220,7 +220,7 @@ impl<'cmd> Usage<'cmd> {
continue;
}
for grp_s in self.cmd.groups_for_arg(f.get_id()) {
debug!("Usage::needs_options_tag:iter:iter: grp_s={:?}", grp_s);
debug!("Usage::needs_options_tag:iter:iter: grp_s={grp_s:?}");
if self.cmd.get_groups().any(|g| g.id == grp_s && g.required) {
debug!("Usage::needs_options_tag:iter:iter: Group is required");
continue 'outer;
Expand All @@ -244,7 +244,7 @@ impl<'cmd> Usage<'cmd> {
}

pub(crate) fn get_args(&self, incls: &[Id], force_optional: bool) -> Vec<StyledStr> {
debug!("Usage::get_args: incls={:?}", incls,);
debug!("Usage::get_args: incls={incls:?}",);
use std::fmt::Write as _;
let literal = &self.styles.get_literal();

Expand Down Expand Up @@ -275,7 +275,7 @@ impl<'cmd> Usage<'cmd> {
// by unroll_requirements_for_arg.
unrolled_reqs.push(a.clone());
}
debug!("Usage::get_args: unrolled_reqs={:?}", unrolled_reqs);
debug!("Usage::get_args: unrolled_reqs={unrolled_reqs:?}");

let mut required_groups_members = FlatSet::new();
let mut required_groups = FlatSet::new();
Expand Down Expand Up @@ -360,7 +360,7 @@ impl<'cmd> Usage<'cmd> {
ret_val.push(pos);
}

debug!("Usage::get_args: ret_val={:?}", ret_val);
debug!("Usage::get_args: ret_val={ret_val:?}");
ret_val
}

Expand Down Expand Up @@ -410,10 +410,7 @@ impl<'cmd> Usage<'cmd> {
// by unroll_requirements_for_arg.
unrolled_reqs.push(a.clone());
}
debug!(
"Usage::get_required_usage_from: unrolled_reqs={:?}",
unrolled_reqs
);
debug!("Usage::get_required_usage_from: unrolled_reqs={unrolled_reqs:?}");

let mut required_groups_members = FlatSet::new();
let mut required_groups = FlatSet::new();
Expand All @@ -427,10 +424,7 @@ impl<'cmd> Usage<'cmd> {
.any(|arg| m.check_explicit(arg, &ArgPredicate::IsPresent))
})
.unwrap_or(false);
debug!(
"Usage::get_required_usage_from:iter:{:?} group is_present={}",
req, is_present
);
debug!("Usage::get_required_usage_from:iter:{req:?} group is_present={is_present}");
if is_present {
continue;
}
Expand All @@ -454,10 +448,7 @@ impl<'cmd> Usage<'cmd> {
let is_present = matcher
.map(|m| m.check_explicit(req, &ArgPredicate::IsPresent))
.unwrap_or(false);
debug!(
"Usage::get_required_usage_from:iter:{:?} arg is_present={}",
req, is_present
);
debug!("Usage::get_required_usage_from:iter:{req:?} arg is_present={is_present}");
if is_present {
continue;
}
Expand Down Expand Up @@ -486,7 +477,7 @@ impl<'cmd> Usage<'cmd> {
ret_val.push(pos);
}

debug!("Usage::get_required_usage_from: ret_val={:?}", ret_val);
debug!("Usage::get_required_usage_from: ret_val={ret_val:?}");
ret_val
}
}
Loading