chore: Inline simple non-mixed format args

This commit is contained in:
Yuri Astrakhan 2023-05-04 15:53:36 -04:00
parent 173f1ede0a
commit d0302c5556
57 changed files with 179 additions and 252 deletions

View file

@ -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() {

View file

@ -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]);
@ -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()
@ -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()
@ -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"));
@ -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() {
@ -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);
}
@ -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()
@ -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![];
@ -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");

View file

@ -482,7 +482,7 @@ fn assert_app_flags(cmd: &Command) {
)+
if !s.is_empty() {
panic!("{}", s)
panic!("{s}")
}
}
};

View file

@ -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);

View file

@ -275,7 +275,7 @@ impl<F: ErrorFormatter> Error<F> {
/// },
/// Err(err) => {
/// let err = err.render();
/// println!("{}", err);
/// println!("{err}");
/// // do_something
/// },
/// };

View file

@ -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()
}};
@ -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! {

View file

@ -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();
@ -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
@ -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
@ -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);
@ -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())
@ -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 {
@ -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()
@ -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);

View file

@ -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}");
@ -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}");

View file

@ -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();
@ -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
}
@ -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;
@ -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();
@ -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();
@ -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
}
@ -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();
@ -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;
}
@ -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;
}
@ -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
}
}

View file

@ -45,10 +45,7 @@ impl ArgMatcher {
}
pub(crate) fn propagate_globals(&mut self, global_arg_vec: &[Id]) {
debug!(
"ArgMatcher::get_global_values: global_arg_vec={:?}",
global_arg_vec
);
debug!("ArgMatcher::get_global_values: global_arg_vec={global_arg_vec:?}");
let mut vals_map = FlatMap::new();
self.fill_in_global_values(global_arg_vec, &mut vals_map);
}
@ -137,10 +134,7 @@ impl ArgMatcher {
pub(crate) fn start_custom_arg(&mut self, arg: &Arg, source: ValueSource) {
let id = arg.get_id().clone();
debug!(
"ArgMatcher::start_custom_arg: id={:?}, source={:?}",
id, source
);
debug!("ArgMatcher::start_custom_arg: id={id:?}, source={source:?}");
let ma = self.entry(id).or_insert(MatchedArg::new_arg(arg));
debug_assert_eq!(ma.type_id(), Some(arg.get_value_parser().type_id()));
ma.set_source(source);
@ -148,10 +142,7 @@ impl ArgMatcher {
}
pub(crate) fn start_custom_group(&mut self, id: Id, source: ValueSource) {
debug!(
"ArgMatcher::start_custom_arg: id={:?}, source={:?}",
id, source
);
debug!("ArgMatcher::start_custom_arg: id={id:?}, source={source:?}");
let ma = self.entry(id).or_insert(MatchedArg::new_group());
debug_assert_eq!(ma.type_id(), None);
ma.set_source(source);
@ -160,7 +151,7 @@ impl ArgMatcher {
pub(crate) fn start_occurrence_of_external(&mut self, cmd: &crate::Command) {
let id = Id::from_static_ref(Id::EXTERNAL);
debug!("ArgMatcher::start_occurrence_of_external: id={:?}", id,);
debug!("ArgMatcher::start_occurrence_of_external: id={id:?}");
let ma = self.entry(id).or_insert(MatchedArg::new_external(cmd));
debug_assert_eq!(
ma.type_id(),
@ -196,10 +187,7 @@ impl ArgMatcher {
num_pending
);
let expected = o.get_num_args().expect(INTERNAL_ERROR_MSG);
debug!(
"ArgMatcher::needs_more_vals: expected={}, actual={}",
expected, num_pending
);
debug!("ArgMatcher::needs_more_vals: expected={expected}, actual={num_pending}");
expected.accepts_more(num_pending)
}

View file

@ -43,7 +43,7 @@ use crate::INTERNAL_ERROR_MSG;
/// // to get information about the "cfg" argument we created, such as the value supplied we use
/// // various ArgMatches methods, such as [ArgMatches::get_one]
/// if let Some(c) = matches.get_one::<String>("cfg") {
/// println!("Value for -c: {}", c);
/// println!("Value for -c: {c}");
/// }
///
/// // The ArgMatches::get_one method returns an Option because the user may not have supplied
@ -924,7 +924,7 @@ impl ArgMatches {
/// ("clone", sub_m) => {}, // clone was used
/// ("push", sub_m) => {}, // push was used
/// ("commit", sub_m) => {}, // commit was used
/// (name, _) => unimplemented!("{}", name),
/// (name, _) => unimplemented!("{name}"),
/// }
/// ```
///

View file

@ -88,7 +88,7 @@ impl<'cmd> Parser<'cmd> {
{
// Does the arg match a subcommand name, or any of its aliases (if defined)
let sc_name = self.possible_subcommand(arg_os.to_value(), valid_arg_found);
debug!("Parser::get_matches_with: sc={:?}", sc_name);
debug!("Parser::get_matches_with: sc={sc_name:?}");
if let Some(sc_name) = sc_name {
if sc_name == "help" && !self.cmd.is_disable_help_subcommand_set() {
ok!(self.parse_help_subcommand(raw_args.remaining(&mut args_cursor)));
@ -120,10 +120,7 @@ impl<'cmd> Parser<'cmd> {
pos_counter,
&mut valid_arg_found,
));
debug!(
"Parser::get_matches_with: After parse_long_arg {:?}",
parse_result
);
debug!("Parser::get_matches_with: After parse_long_arg {parse_result:?}");
match parse_result {
ParseResult::NoArg => {
unreachable!("`to_long` always has the flag specified")
@ -193,10 +190,7 @@ impl<'cmd> Parser<'cmd> {
&mut valid_arg_found,
));
// If it's None, we then check if one of those two AppSettings was set
debug!(
"Parser::get_matches_with: After parse_short_arg {:?}",
parse_result
);
debug!("Parser::get_matches_with: After parse_short_arg {parse_result:?}");
match parse_result {
ParseResult::NoArg => {
// Is a single dash `-`, try positional.
@ -312,14 +306,8 @@ impl<'cmd> Parser<'cmd> {
&& is_second_to_last
&& !trailing_values;
debug!(
"Parser::get_matches_with: Positional counter...{}",
pos_counter
);
debug!(
"Parser::get_matches_with: Low index multiples...{:?}",
low_index_mults
);
debug!("Parser::get_matches_with: Positional counter...{pos_counter}");
debug!("Parser::get_matches_with: Low index multiples...{low_index_mults:?}");
if low_index_mults || missing_pos {
let skip_current = if let Some(n) = raw_args.peek(&args_cursor) {
@ -386,8 +374,7 @@ impl<'cmd> Parser<'cmd> {
}
if let Some(_parse_result) = self.check_terminator(arg, arg_os.to_value_os()) {
debug!(
"Parser::get_matches_with: ignoring terminator result {:?}",
_parse_result
"Parser::get_matches_with: ignoring terminator result {_parse_result:?}"
);
} else {
let arg_values = matcher.pending_values_mut(
@ -535,7 +522,7 @@ impl<'cmd> Parser<'cmd> {
arg: Result<&str, &OsStr>,
valid_arg_found: bool,
) -> Option<&str> {
debug!("Parser::possible_subcommand: arg={:?}", arg);
debug!("Parser::possible_subcommand: arg={arg:?}");
let arg = some!(arg.ok());
if !(self.cmd.is_args_conflicts_with_subcommands_set() && valid_arg_found) {
@ -564,7 +551,7 @@ impl<'cmd> Parser<'cmd> {
// Checks if the arg matches a long flag subcommand name, or any of its aliases (if defined)
fn possible_long_flag_subcommand(&self, arg: &str) -> Option<&str> {
debug!("Parser::possible_long_flag_subcommand: arg={:?}", arg);
debug!("Parser::possible_long_flag_subcommand: arg={arg:?}");
if self.cmd.is_infer_subcommands_set() {
let options = self
.cmd
@ -687,10 +674,7 @@ impl<'cmd> Parser<'cmd> {
}
if let Err(error) = p.get_matches_with(&mut sc_matcher, raw_args, args_cursor) {
if partial_parsing_enabled {
debug!(
"Parser::parse_subcommand: ignored error in subcommand {}: {:?}",
sc_name, error
);
debug!("Parser::parse_subcommand: ignored error in subcommand {sc_name}: {error:?}");
} else {
return Err(error);
}
@ -741,7 +725,7 @@ impl<'cmd> Parser<'cmd> {
}
let arg = if let Some(arg) = self.cmd.get_keymap().get(long_arg) {
debug!("Parser::parse_long_arg: Found valid arg or flag '{}'", arg);
debug!("Parser::parse_long_arg: Found valid arg or flag '{arg}'");
Some((long_arg, arg))
} else if self.cmd.is_infer_long_args_set() {
self.cmd.get_arguments().find_map(|a| {
@ -770,10 +754,7 @@ impl<'cmd> Parser<'cmd> {
self.parse_opt_value(ident, long_value, arg, matcher, has_eq)
} else if let Some(rest) = long_value {
let required = self.cmd.required_graph();
debug!(
"Parser::parse_long_arg({:?}): Got invalid literal `{:?}`",
long_arg, rest
);
debug!("Parser::parse_long_arg({long_arg:?}): Got invalid literal `{rest:?}`");
let mut used: Vec<Id> = matcher
.arg_ids()
.filter(|arg_id| {
@ -795,7 +776,7 @@ impl<'cmd> Parser<'cmd> {
arg: arg.to_string(),
})
} else {
debug!("Parser::parse_long_arg({:?}): Presence validated", long_arg);
debug!("Parser::parse_long_arg({long_arg:?}): Presence validated");
let trailing_idx = None;
self.react(
Some(ident),
@ -815,10 +796,7 @@ impl<'cmd> Parser<'cmd> {
.map(|arg| arg.is_allow_hyphen_values_set() && !arg.is_last_set())
.unwrap_or_default()
{
debug!(
"Parser::parse_long_args: positional at {} allows hyphens",
pos_counter
);
debug!("Parser::parse_long_args: positional at {pos_counter} allows hyphens");
Ok(ParseResult::MaybeHyphenValue)
} else {
Ok(ParseResult::NoMatchingArg {
@ -836,7 +814,7 @@ impl<'cmd> Parser<'cmd> {
pos_counter: usize,
valid_arg_found: &mut bool,
) -> ClapResult<ParseResult> {
debug!("Parser::parse_short_arg: short_arg={:?}", short_arg);
debug!("Parser::parse_short_arg: short_arg={short_arg:?}");
#[allow(clippy::blocks_in_if_conditions)]
if matches!(parse_state, ParseState::Opt(opt) | ParseState::Pos(opt)
@ -864,10 +842,7 @@ impl<'cmd> Parser<'cmd> {
.clone()
.any(|c| !c.map(|c| self.cmd.contains_short(c)).unwrap_or_default())
{
debug!(
"Parser::parse_short_args: positional at {} allows hyphens",
pos_counter
);
debug!("Parser::parse_short_args: positional at {pos_counter} allows hyphens");
return Ok(ParseResult::MaybeHyphenValue);
}
@ -890,7 +865,7 @@ impl<'cmd> Parser<'cmd> {
});
}
};
debug!("Parser::parse_short_arg:iter:{}", c);
debug!("Parser::parse_short_arg:iter:{c}");
// Check for matching short options, and return the name if there is no trailing
// concatenated value: -oval
@ -898,10 +873,7 @@ impl<'cmd> Parser<'cmd> {
// Value: val
if let Some(arg) = self.cmd.get_keymap().get(&c) {
let ident = Identifier::Short;
debug!(
"Parser::parse_short_arg:iter:{}: Found valid opt or flag",
c
);
debug!("Parser::parse_short_arg:iter:{c}: Found valid opt or flag");
*valid_arg_found = true;
if !arg.is_takes_value_set() {
let arg_values = Vec::new();
@ -921,10 +893,7 @@ impl<'cmd> Parser<'cmd> {
//
// Cloning the iterator, so we rollback if it isn't there.
let val = short_arg.clone().next_value_os().unwrap_or_default();
debug!(
"Parser::parse_short_arg:iter:{}: val={:?}, short_arg={:?}",
c, val, short_arg
);
debug!("Parser::parse_short_arg:iter:{c}: val={val:?}, short_arg={short_arg:?}");
let val = Some(val).filter(|v| !v.is_empty());
// Default to "we're expecting a value later".
@ -946,7 +915,7 @@ impl<'cmd> Parser<'cmd> {
}
return if let Some(sc_name) = self.cmd.find_short_subcmd(c) {
debug!("Parser::parse_short_arg:iter:{}: subcommand={}", c, sc_name);
debug!("Parser::parse_short_arg:iter:{c}: subcommand={sc_name}");
// Make sure indices get updated before reading `self.cur_idx`
ok!(self.resolve_pending(matcher));
self.cur_idx.set(self.cur_idx.get() + 1);
@ -1053,7 +1022,7 @@ impl<'cmd> Parser<'cmd> {
raw_vals: Vec<OsString>,
matcher: &mut ArgMatcher,
) -> ClapResult<()> {
debug!("Parser::push_arg_values: {:?}", raw_vals);
debug!("Parser::push_arg_values: {raw_vals:?}");
for raw_val in raw_vals {
// update the current index because each value is a distinct index to clap
@ -1262,7 +1231,7 @@ impl<'cmd> Parser<'cmd> {
Some(Identifier::Index) => true,
None => true,
};
debug!("Help: use_long={}", use_long);
debug!("Help: use_long={use_long}");
Err(self.help_err(use_long))
}
ArgAction::Version => {
@ -1272,7 +1241,7 @@ impl<'cmd> Parser<'cmd> {
Some(Identifier::Index) => true,
None => true,
};
debug!("Version: use_long={}", use_long);
debug!("Version: use_long={use_long}");
Err(self.version_err(use_long))
}
}
@ -1337,7 +1306,7 @@ impl<'cmd> Parser<'cmd> {
fn remove_overrides(&self, arg: &Arg, matcher: &mut ArgMatcher) {
debug!("Parser::remove_overrides: id={:?}", arg.id);
for override_id in &arg.overrides {
debug!("Parser::remove_overrides:iter:{:?}: removing", override_id);
debug!("Parser::remove_overrides:iter:{override_id:?}: removing");
matcher.remove(override_id);
}
@ -1351,7 +1320,7 @@ impl<'cmd> Parser<'cmd> {
}
}
for overrider_id in transitive {
debug!("Parser::remove_overrides:iter:{:?}: removing", overrider_id);
debug!("Parser::remove_overrides:iter:{overrider_id:?}: removing");
matcher.remove(overrider_id);
}
}
@ -1364,13 +1333,13 @@ impl<'cmd> Parser<'cmd> {
// Use env only if the arg was absent among command line args,
// early return if this is not the case.
if matcher.contains(&arg.id) {
debug!("Parser::add_env: Skipping existing arg `{}`", arg);
debug!("Parser::add_env: Skipping existing arg `{arg}`");
continue;
}
debug!("Parser::add_env: Checking arg `{}`", arg);
debug!("Parser::add_env: Checking arg `{arg}`");
if let Some((_, Some(ref val))) = arg.env {
debug!("Parser::add_env: Found an opt with value={:?}", val);
debug!("Parser::add_env: Found an opt with value={val:?}");
let arg_values = vec![val.to_owned()];
let trailing_idx = None;
let _ = ok!(self.react(
@ -1504,7 +1473,7 @@ impl<'cmd> Parser<'cmd> {
remaining_args: &[&OsStr],
trailing_values: bool,
) -> ClapError {
debug!("Parser::did_you_mean_error: arg={}", arg);
debug!("Parser::did_you_mean_error: arg={arg}");
// Didn't match a flag or option
let longs = self
.cmd
@ -1515,7 +1484,7 @@ impl<'cmd> Parser<'cmd> {
_ => None,
})
.collect::<Vec<_>>();
debug!("Parser::did_you_mean_error: longs={:?}", longs);
debug!("Parser::did_you_mean_error: longs={longs:?}");
let did_you_mean = suggestions::did_you_mean_flag(
arg,

View file

@ -31,7 +31,7 @@ impl<'cmd> Validator<'cmd> {
let has_subcmd = matcher.subcommand_name().is_some();
if let ParseState::Opt(a) = parse_state {
debug!("Validator::validate: needs_val_of={:?}", a);
debug!("Validator::validate: needs_val_of={a:?}");
let o = &self.cmd[&a];
let should_err = if let Some(v) = matcher.args.get(o.get_id()) {
@ -102,7 +102,7 @@ impl<'cmd> Validator<'cmd> {
.filter(|(_, matched)| matched.check_explicit(&ArgPredicate::IsPresent))
.filter(|(arg_id, _)| self.cmd.find(arg_id).is_some())
{
debug!("Validator::validate_conflicts::iter: id={:?}", arg_id);
debug!("Validator::validate_conflicts::iter: id={arg_id:?}");
let conflicts = conflicts.gather_conflicts(self.cmd, arg_id);
ok!(self.build_conflict_err(arg_id, &conflicts, matcher));
}
@ -130,7 +130,7 @@ impl<'cmd> Validator<'cmd> {
.args()
.filter(|(_, matched)| matched.check_explicit(&crate::builder::ArgPredicate::IsPresent))
.filter_map(|(id, _)| {
debug!("Validator::validate_exclusive:iter:{:?}", id);
debug!("Validator::validate_exclusive:iter:{id:?}");
self.cmd
.find(id)
// Find `arg`s which are exclusive but also appear with other args.
@ -159,7 +159,7 @@ impl<'cmd> Validator<'cmd> {
return Ok(());
}
debug!("Validator::build_conflict_err: name={:?}", name);
debug!("Validator::build_conflict_err: name={name:?}");
let mut seen = FlatSet::new();
let conflicts = conflict_ids
.iter()
@ -226,7 +226,7 @@ impl<'cmd> Validator<'cmd> {
.args()
.filter(|(_, matched)| matched.check_explicit(&ArgPredicate::IsPresent))
{
debug!("Validator::gather_requires:iter:{:?}", name);
debug!("Validator::gather_requires:iter:{name:?}");
if let Some(arg) = self.cmd.find(name) {
let is_relevant = |(val, req_arg): &(ArgPredicate, Id)| -> Option<Id> {
let required = matched.check_explicit(val);
@ -237,7 +237,7 @@ impl<'cmd> Validator<'cmd> {
self.required.insert(req);
}
} else if let Some(g) = self.cmd.find_group(name) {
debug!("Validator::gather_requires:iter:{:?}:group", name);
debug!("Validator::gather_requires:iter:{name:?}:group");
for r in &g.requires {
self.required.insert(r.clone());
}
@ -261,17 +261,14 @@ impl<'cmd> Validator<'cmd> {
.map(|arg| arg.is_exclusive_set())
.unwrap_or_default()
});
debug!(
"Validator::validate_required: is_exclusive_present={}",
is_exclusive_present
);
debug!("Validator::validate_required: is_exclusive_present={is_exclusive_present}");
for arg_or_group in self
.required
.iter()
.filter(|r| !matcher.check_explicit(r, &ArgPredicate::IsPresent))
{
debug!("Validator::validate_required:iter:aog={:?}", arg_or_group);
debug!("Validator::validate_required:iter:aog={arg_or_group:?}");
if let Some(arg) = self.cmd.find(arg_or_group) {
debug!("Validator::validate_required:iter: This is an arg");
if !is_exclusive_present && !self.is_missing_required_ok(arg, conflicts) {
@ -380,7 +377,7 @@ impl<'cmd> Validator<'cmd> {
}
for group_id in self.cmd.groups_for_arg(a.get_id()) {
if !conflicts.gather_conflicts(self.cmd, &group_id).is_empty() {
debug!("Validator::is_missing_required_ok: true ({})", group_id);
debug!("Validator::is_missing_required_ok: true ({group_id})");
return true;
}
}
@ -402,7 +399,7 @@ impl<'cmd> Validator<'cmd> {
matcher: &ArgMatcher,
raw_req_args: Vec<Id>,
) -> ClapResult<()> {
debug!("Validator::missing_required_error; incl={:?}", raw_req_args);
debug!("Validator::missing_required_error; incl={raw_req_args:?}");
debug!(
"Validator::missing_required_error: reqs={:?}",
self.required
@ -429,7 +426,7 @@ impl<'cmd> Validator<'cmd> {
} else if let Some(_group) = self.cmd.find_group(id) {
self.cmd.format_group(id).to_string()
} else {
debug_assert!(false, "id={:?} is unknown", id);
debug_assert!(false, "id={id:?} is unknown");
"".to_owned()
}
})
@ -437,10 +434,7 @@ impl<'cmd> Validator<'cmd> {
}
};
debug!(
"Validator::missing_required_error: req_args={:#?}",
req_args
);
debug!("Validator::missing_required_error: req_args={req_args:#?}");
let used: Vec<Id> = matcher
.args()
@ -486,7 +480,7 @@ impl Conflicts {
}
fn gather_conflicts(&self, cmd: &Command, arg_id: &Id) -> Vec<Id> {
debug!("Conflicts::gather_conflicts: arg={:?}", arg_id);
debug!("Conflicts::gather_conflicts: arg={arg_id:?}");
let mut conflicts = Vec::new();
let arg_id_conflicts_storage;
@ -510,7 +504,7 @@ impl Conflicts {
}
}
debug!("Conflicts::gather_conflicts: conflicts={:?}", conflicts);
debug!("Conflicts::gather_conflicts: conflicts={conflicts:?}");
conflicts
}

View file

@ -27,7 +27,7 @@ fn main() {
{
completions.complete(&mut command());
} else {
println!("{:#?}", matches);
println!("{matches:#?}");
}
}

View file

@ -71,7 +71,7 @@ pub mod bash {
/// Process the completion request
pub fn try_complete(&self, cmd: &mut clap::Command) -> clap::error::Result<()> {
debug!("CompleteCommand::try_complete: {:?}", self);
debug!("CompleteCommand::try_complete: {self:?}");
let CompleteCommand::Complete(args) = self;
if let Some(out_path) = args.register.as_deref() {
let mut buf = Vec::new();
@ -124,7 +124,7 @@ pub mod bash {
/// The recommended file name for the registration code
pub fn file_name(name: &str) -> String {
format!("{}.bash", name)
format!("{name}.bash")
}
/// Define the completion behavior
@ -154,8 +154,7 @@ pub mod bash {
let escaped_name = name.replace('-', "_");
debug_assert!(
escaped_name.chars().all(|c| c.is_xid_continue()),
"`name` must be an identifier, got `{}`",
escaped_name
"`name` must be an identifier, got `{escaped_name}`"
);
let mut upper_name = escaped_name.clone();
upper_name.make_ascii_uppercase();
@ -201,7 +200,7 @@ complete OPTIONS -F _clap_complete_NAME EXECUTABLES
.replace("COMPLETER", &completer)
.replace("UPPER", &upper_name);
writeln!(buf, "{}", script)?;
writeln!(buf, "{script}")?;
Ok(())
}
@ -386,7 +385,7 @@ complete OPTIONS -F _clap_complete_NAME EXECUTABLES
crate::generator::utils::longs_and_visible_aliases(cmd)
.into_iter()
.filter_map(|f| {
f.starts_with(flag).then(|| format!("--{}", f).into())
f.starts_with(flag).then(|| format!("--{f}").into())
}),
);
}
@ -396,7 +395,7 @@ complete OPTIONS -F _clap_complete_NAME EXECUTABLES
completions.extend(
crate::generator::utils::longs_and_visible_aliases(cmd)
.into_iter()
.map(|f| format!("--{}", f).into()),
.map(|f| format!("--{f}").into()),
);
}
@ -431,7 +430,7 @@ complete OPTIONS -F _clap_complete_NAME EXECUTABLES
current_dir: Option<&std::path::Path>,
) -> Vec<OsString> {
let mut values = Vec::new();
debug!("complete_arg_value: arg={:?}, value={:?}", arg, value);
debug!("complete_arg_value: arg={arg:?}, value={value:?}");
if let Some(possible_values) = crate::generator::utils::possible_values(arg) {
if let Ok(value) = value {
@ -500,7 +499,7 @@ complete OPTIONS -F _clap_complete_NAME EXECUTABLES
.split_once("\\")
.unwrap_or((OsStr::new(""), value_os));
let root = current_dir.join(existing);
debug!("complete_path: root={:?}, prefix={:?}", root, prefix);
debug!("complete_path: root={root:?}, prefix={prefix:?}");
let prefix = prefix.to_string_lossy();
for entry in std::fs::read_dir(&root)

View file

@ -29,7 +29,7 @@ pub trait Generator {
///
/// impl Generator for Fish {
/// fn file_name(&self, name: &str) -> String {
/// format!("{}.fish", name)
/// format!("{name}.fish")
/// }
/// # fn generate(&self, cmd: &Command, buf: &mut dyn Write) {}
/// }
@ -59,7 +59,7 @@ pub trait Generator {
/// # name.into()
/// # }
/// fn generate(&self, cmd: &Command, buf: &mut dyn Write) {
/// write!(buf, "{}", cmd).unwrap();
/// write!(buf, "{cmd}").unwrap();
/// }
/// }
/// ```
@ -150,7 +150,7 @@ pub trait Generator {
/// outdir, // We need to specify where to write to
/// )?;
///
/// println!("cargo:warning=completion file is generated: {:?}", path);
/// println!("cargo:warning=completion file is generated: {path:?}");
///
/// Ok(())
/// }

View file

@ -49,7 +49,7 @@
//!
//! if let Some(generator) = matches.get_one::<Shell>("generator").copied() {
//! let mut cmd = build_cli();
//! eprintln!("Generating completion file for {}...", generator);
//! eprintln!("Generating completion file for {generator}...");
//! print_completions(generator, &mut cmd);
//! }
//! }

View file

@ -158,7 +158,7 @@ fn subcommand_details(cmd: &Command) -> String {
}
fn option_details_for_path(cmd: &Command, path: &str) -> String {
debug!("option_details_for_path: path={}", path);
debug!("option_details_for_path: path={path}");
let p = utils::find_subcommand_with_path(cmd, path.split("__").skip(1).collect());
let mut opts = vec![String::new()];
@ -212,7 +212,7 @@ fn vals_for(o: &Arg) -> String {
}
fn all_options_for_path(cmd: &Command, path: &str) -> String {
debug!("all_options_for_path: path={}", path);
debug!("all_options_for_path: path={path}");
let p = utils::find_subcommand_with_path(cmd, path.split("__").skip(1).collect());

View file

@ -80,7 +80,7 @@ fn gen_fish_inner(
);
}
debug!("gen_fish_inner: parent_commands={:?}", parent_commands);
debug!("gen_fish_inner: parent_commands={parent_commands:?}");
for option in cmd.get_opts() {
let mut template = basic_template.clone();

View file

@ -95,11 +95,8 @@ fn generate_inner(p: &Command, previous_command_name: &str) -> String {
completions.push_str(&preamble);
completions.push_str(
format!(
"'{}', '{}', {}, '{}')",
data, data, "[CompletionResultType]::ParameterValue", tooltip
)
.as_str(),
format!("'{data}', '{data}', [CompletionResultType]::ParameterValue, '{tooltip}')")
.as_str(),
);
}

View file

@ -657,7 +657,7 @@ fn write_positionals_of(p: &Command) -> String {
value_completion = value_completion(arg).unwrap_or_default()
);
debug!("write_positionals_of:iter: Wrote...{}", a);
debug!("write_positionals_of:iter: Wrote...{a}");
ret.push(a);
}

View file

@ -53,7 +53,7 @@ fn escape_string(string: &str) -> String {
fn gen_fig_inner(parent_commands: &[&str], indent: usize, cmd: &Command, buffer: &mut String) {
if cmd.has_subcommands() {
write!(buffer, "{:indent$}subcommands: [\n", "", indent = indent).unwrap();
write!(buffer, "{:indent$}subcommands: [\n", "").unwrap();
// generate subcommands
for subcommand in cmd.get_subcommands() {
let mut aliases: Vec<&str> = subcommand.get_all_aliases().collect();
@ -111,7 +111,7 @@ fn gen_fig_inner(parent_commands: &[&str], indent: usize, cmd: &Command, buffer:
write!(buffer, "{:indent$}}},\n", "", indent = indent + 2).unwrap();
}
write!(buffer, "{:indent$}],\n", "", indent = indent).unwrap();
write!(buffer, "{:indent$}],\n", "").unwrap();
}
buffer.push_str(&gen_options(cmd, indent));
@ -121,17 +121,17 @@ fn gen_fig_inner(parent_commands: &[&str], indent: usize, cmd: &Command, buffer:
match args.len() {
0 => {}
1 => {
write!(buffer, "{:indent$}args: ", "", indent = indent).unwrap();
write!(buffer, "{:indent$}args: ", "").unwrap();
buffer.push_str(&gen_args(args[0], indent));
}
_ => {
write!(buffer, "{:indent$}args: [\n", "", indent = indent).unwrap();
write!(buffer, "{:indent$}args: [\n", "").unwrap();
for arg in args {
write!(buffer, "{:indent$}", "", indent = indent + 2).unwrap();
buffer.push_str(&gen_args(arg, indent + 2));
}
write!(buffer, "{:indent$}]\n", "", indent = indent).unwrap();
write!(buffer, "{:indent$}]\n", "").unwrap();
}
};
}
@ -142,7 +142,7 @@ fn gen_options(cmd: &Command, indent: usize) -> String {
let flags = generator::utils::flags(cmd);
if cmd.get_opts().next().is_some() || !flags.is_empty() {
write!(&mut buffer, "{:indent$}options: [\n", "", indent = indent).unwrap();
write!(&mut buffer, "{:indent$}options: [\n", "").unwrap();
for option in cmd.get_opts() {
write!(&mut buffer, "{:indent$}{{\n", "", indent = indent + 2).unwrap();
@ -346,7 +346,7 @@ fn gen_options(cmd: &Command, indent: usize) -> String {
write!(&mut buffer, "{:indent$}}},\n", "", indent = indent + 2).unwrap();
}
write!(&mut buffer, "{:indent$}],\n", "", indent = indent).unwrap();
write!(&mut buffer, "{:indent$}],\n", "").unwrap();
}
buffer
@ -467,7 +467,7 @@ fn gen_args(arg: &Arg, indent: usize) -> String {
};
};
write!(&mut buffer, "{:indent$}}},\n", "", indent = indent).unwrap();
write!(&mut buffer, "{:indent$}}},\n", "").unwrap();
buffer
}

View file

@ -908,7 +908,7 @@ impl Item {
if !lines.is_empty() {
let (short_help, long_help) =
format_doc_comment(&lines, !self.verbatim_doc_comment, self.force_long_help);
let short_name = format_ident!("{}", short_name);
let short_name = format_ident!("{short_name}");
let short = Method::new(
short_name,
short_help
@ -917,7 +917,7 @@ impl Item {
);
self.doc_comment.push(short);
if let Some(long_name) = long_name {
let long_name = format_ident!("{}", long_name);
let long_name = format_ident!("{long_name}");
let long = Method::new(
long_name,
long_help
@ -946,7 +946,7 @@ impl Item {
(_, _) => {
let old = self.kind.name();
let new = kind.name();
abort!(kind.span(), "`{}` cannot be used with `{}`", new, old);
abort!(kind.span(), "`{new}` cannot be used with `{old}`");
}
}
Ok(())
@ -1405,7 +1405,7 @@ impl CasingStyle {
"lower" | "lowercase" => cs(Lower),
"upper" | "uppercase" => cs(Upper),
"verbatim" | "verbatimcase" => cs(Verbatim),
s => abort!(name, "unsupported casing: `{}`", s),
s => abort!(name, "unsupported casing: `{s}`"),
};
Ok(s)
}

View file

@ -40,7 +40,7 @@
//! Ok(Color::Never)
//! }
//! Some(invalid) => {
//! Err(format!("Invalid value for `--color`, {:?}", invalid).into())
//! Err(format!("Invalid value for `--color`, {invalid:?}").into())
//! }
//! }
//! }
@ -67,7 +67,7 @@
//! match long {
//! Ok("verbose") => {
//! if let Some(value) = value {
//! return Err(format!("`--verbose` does not take a value, got `{:?}`", value).into());
//! return Err(format!("`--verbose` does not take a value, got `{value:?}`").into());
//! }
//! args.verbosity += 1;
//! }
@ -91,7 +91,7 @@
//! args.color = Color::parse(value)?;
//! }
//! Ok(c) => {
//! return Err(format!("Unexpected flag: -{}", c).into());
//! return Err(format!("Unexpected flag: -{c}").into());
//! }
//! Err(e) => {
//! return Err(format!("Unexpected flag: -{}", e.to_string_lossy()).into());
@ -107,7 +107,7 @@
//! }
//!
//! let args = parse_args(["bin", "--hello", "world"]);
//! println!("{:?}", args);
//! println!("{args:?}");
//! ```
mod ext;
@ -139,7 +139,7 @@ impl RawArgs {
/// let _bin = raw.next_os(&mut cursor);
///
/// let mut paths = raw.remaining(&mut cursor).map(PathBuf::from).collect::<Vec<_>>();
/// println!("{:?}", paths);
/// println!("{paths:?}");
/// ```
pub fn from_args() -> Self {
Self::new(std::env::args_os())
@ -156,7 +156,7 @@ impl RawArgs {
/// let _bin = raw.next_os(&mut cursor);
///
/// let mut paths = raw.remaining(&mut cursor).map(PathBuf::from).collect::<Vec<_>>();
/// println!("{:?}", paths);
/// println!("{paths:?}");
/// ```
pub fn new(iter: impl IntoIterator<Item = impl Into<std::ffi::OsString>>) -> Self {
let iter = iter.into_iter();
@ -174,7 +174,7 @@ impl RawArgs {
/// let _bin = raw.next_os(&mut cursor);
///
/// let mut paths = raw.remaining(&mut cursor).map(PathBuf::from).collect::<Vec<_>>();
/// println!("{:?}", paths);
/// println!("{paths:?}");
/// ```
pub fn cursor(&self) -> ArgCursor {
ArgCursor::new()
@ -213,7 +213,7 @@ impl RawArgs {
/// let _bin = raw.next_os(&mut cursor);
///
/// let mut paths = raw.remaining(&mut cursor).map(PathBuf::from).collect::<Vec<_>>();
/// println!("{:?}", paths);
/// println!("{paths:?}");
/// ```
pub fn remaining(&self, cursor: &mut ArgCursor) -> impl Iterator<Item = &OsStr> {
let remaining = self.items[cursor.cursor..].iter().map(|s| s.as_os_str());

View file

@ -14,5 +14,5 @@ fn main() {
_ => unreachable!("clap should ensure we don't get here"),
};
let manifest_path = matches.get_one::<std::path::PathBuf>("manifest-path");
println!("{:?}", manifest_path);
println!("{manifest_path:?}");
}

View file

@ -5,7 +5,7 @@ use clap::{arg, command, ArgGroup, ArgMatches, Command};
fn main() {
let matches = cli().get_matches();
let values = Value::from_matches(&matches);
println!("{:#?}", values);
println!("{values:#?}");
}
fn cli() -> Command {
@ -51,7 +51,7 @@ impl Value {
if Self::extract::<bool>(matches, id, &mut values) {
continue;
}
unimplemented!("unknown type for {}: {:?}", id, matches);
unimplemented!("unknown type for {id}: {matches:?}");
}
values.into_values().collect::<Vec<_>>()
}

View file

@ -118,7 +118,7 @@ fn main() {
println!("Pushing {message:?}");
}
(name, _) => {
unreachable!("Unsupported subcommand `{}`", name)
unreachable!("Unsupported subcommand `{name}`")
}
}
}

View file

@ -41,7 +41,7 @@ fn respond(line: &str) -> Result<bool, String> {
std::io::stdout().flush().map_err(|e| e.to_string())?;
return Ok(true);
}
Some((name, _matches)) => unimplemented!("{}", name),
Some((name, _matches)) => unimplemented!("{name}"),
None => unreachable!("subcommand required"),
}

View file

@ -25,7 +25,7 @@ fn main() {
// You can check the value provided by positional arguments, or option arguments
if let Some(name) = matches.get_one::<String>("name") {
println!("Value for name: {}", name);
println!("Value for name: {name}");
}
if let Some(config_path) = matches.get_one::<PathBuf>("config") {

View file

@ -38,7 +38,7 @@ impl std::str::FromStr for Mode {
return Ok(*variant);
}
}
Err(format!("invalid variant: {}", s))
Err(format!("invalid variant: {s}"))
}
}

View file

@ -13,5 +13,5 @@ fn main() {
let port: u16 = *matches
.get_one::<u16>("PORT")
.expect("'PORT' is required and parsing will fail if its missing");
println!("PORT = {}", port);
println!("PORT = {port}");
}

View file

@ -15,7 +15,7 @@ fn main() {
let port: u16 = *matches
.get_one::<u16>("PORT")
.expect("'PORT' is required and parsing will fail if its missing");
println!("PORT = {}", port);
println!("PORT = {port}");
}
const PORT_RANGE: RangeInclusive<usize> = 1..=65535;
@ -23,7 +23,7 @@ const PORT_RANGE: RangeInclusive<usize> = 1..=65535;
fn port_in_range(s: &str) -> Result<u16, String> {
let port: usize = s
.parse()
.map_err(|_| format!("`{}` isn't a port number", s))?;
.map_err(|_| format!("`{s}` isn't a port number"))?;
if PORT_RANGE.contains(&port) {
Ok(port as u16)
} else {

View file

@ -58,10 +58,10 @@ fn main() {
(_, _, true) => patch += 1,
_ => unreachable!(),
};
format!("{}.{}.{}", major, minor, patch)
format!("{major}.{minor}.{patch}")
};
println!("Version: {}", version);
println!("Version: {version}");
// Check for usage of -c
if matches.contains_id("config") {

View file

@ -57,10 +57,10 @@ fn main() {
.exit();
}
};
format!("{}.{}.{}", major, minor, patch)
format!("{major}.{minor}.{patch}")
};
println!("Version: {}", version);
println!("Version: {version}");
// Check for usage of -c
if matches.contains_id("config") {

View file

@ -7,7 +7,7 @@ fn main() {
let port: usize = *matches
.get_one::<usize>("PORT")
.expect("'PORT' is required and parsing will fail if its missing");
println!("PORT = {}", port);
println!("PORT = {port}");
}
fn cmd() -> clap::Command {

View file

@ -121,17 +121,17 @@ fn arg_conflicts_with_group() {
let result = cmd.try_get_matches_from_mut(vec!["myprog", "--some"]);
if let Err(err) = result {
panic!("{}", err);
panic!("{err}");
}
let result = cmd.try_get_matches_from_mut(vec!["myprog", "--other"]);
if let Err(err) = result {
panic!("{}", err);
panic!("{err}");
}
let result = cmd.try_get_matches_from_mut(vec!["myprog", "--flag"]);
if let Err(err) = result {
panic!("{}", err);
panic!("{err}");
}
}
@ -149,17 +149,17 @@ fn arg_conflicts_with_group_with_multiple_sources() {
let result = cmd.try_get_matches_from_mut(vec!["myprog", "-f"]);
if let Err(err) = result {
panic!("{}", err);
panic!("{err}");
}
let result = cmd.try_get_matches_from_mut(vec!["myprog", "--some", "usb1"]);
if let Err(err) = result {
panic!("{}", err);
panic!("{err}");
}
let result = cmd.try_get_matches_from_mut(vec!["myprog", "--some", "usb1", "--other", "40"]);
if let Err(err) = result {
panic!("{}", err);
panic!("{err}");
}
let result = cmd.try_get_matches_from_mut(vec!["myprog", "-f", "--some", "usb1"]);
@ -192,17 +192,17 @@ fn group_conflicts_with_arg() {
let result = cmd.try_get_matches_from_mut(vec!["myprog", "--some"]);
if let Err(err) = result {
panic!("{}", err);
panic!("{err}");
}
let result = cmd.try_get_matches_from_mut(vec!["myprog", "--other"]);
if let Err(err) = result {
panic!("{}", err);
panic!("{err}");
}
let result = cmd.try_get_matches_from_mut(vec!["myprog", "--flag"]);
if let Err(err) = result {
panic!("{}", err);
panic!("{err}");
}
}
@ -226,12 +226,12 @@ fn arg_conflicts_with_required_group() {
let result = cmd.try_get_matches_from_mut(vec!["myprog", "--some"]);
if let Err(err) = result {
panic!("{}", err);
panic!("{err}");
}
let result = cmd.try_get_matches_from_mut(vec!["myprog", "--other"]);
if let Err(err) = result {
panic!("{}", err);
panic!("{err}");
}
}
@ -255,12 +255,12 @@ fn arg_conflicts_with_group_with_required_memeber() {
let result = cmd.try_get_matches_from_mut(vec!["myprog", "--some"]);
if let Err(err) = result {
panic!("{}", err);
panic!("{err}");
}
let result = cmd.try_get_matches_from_mut(vec!["myprog", "--flag"]);
if let Err(err) = result {
panic!("{}", err);
panic!("{err}");
}
}
@ -290,12 +290,12 @@ fn required_group_conflicts_with_arg() {
let result = cmd.try_get_matches_from_mut(vec!["myprog", "--some"]);
if let Err(err) = result {
panic!("{}", err);
panic!("{err}");
}
let result = cmd.try_get_matches_from_mut(vec!["myprog", "--other"]);
if let Err(err) = result {
panic!("{}", err);
panic!("{err}");
}
}

View file

@ -1531,7 +1531,7 @@ fn values_per_occurrence_named() {
]);
let m = match m {
Ok(m) => m,
Err(err) => panic!("{}", err),
Err(err) => panic!("{err}"),
};
assert_eq!(
m.get_many::<String>("pos")

View file

@ -9,5 +9,5 @@ struct Opt {
fn main() {
let opt = Opt::parse();
println!("{:?}", opt);
println!("{opt:?}");
}

View file

@ -12,5 +12,5 @@ struct Opt1 {
fn main() {
let opt = Opt::parse();
println!("{:?}", opt);
println!("{opt:?}");
}

View file

@ -17,5 +17,5 @@ struct Opt {
fn main() {
let opt = Opt::parse();
println!("{:?}", opt);
println!("{opt:?}");
}

View file

@ -9,5 +9,5 @@ struct Opt {
fn main() {
let opt = Opt::parse();
println!("{:?}", opt);
println!("{opt:?}");
}

View file

@ -17,5 +17,5 @@ enum Opt {
fn main() {
let opt = Opt::parse();
println!("{:?}", opt);
println!("{opt:?}");
}

View file

@ -25,5 +25,5 @@ struct Opt {
fn main() {
let opt = Opt::parse();
println!("{:?}", opt);
println!("{opt:?}");
}

View file

@ -19,5 +19,5 @@ struct Source {
fn main() {
let opt = Opt::parse();
println!("{:?}", opt);
println!("{opt:?}");
}

View file

@ -17,5 +17,5 @@ enum Command {
fn main() {
let opt = Opt::parse();
println!("{:?}", opt);
println!("{opt:?}");
}

View file

@ -17,5 +17,5 @@ struct Opt {
fn main() {
let opt = Opt::parse();
println!("{:?}", opt);
println!("{opt:?}");
}

View file

@ -17,5 +17,5 @@ struct Opt {
fn main() {
let opt = Opt::parse();
println!("{:?}", opt);
println!("{opt:?}");
}

View file

@ -38,5 +38,5 @@ impl Default for Command {
fn main() {
let opt = MakeCookie::parse();
println!("{:?}", opt);
println!("{opt:?}");
}

View file

@ -38,5 +38,5 @@ impl Default for Command {
fn main() {
let opt = MakeCookie::parse();
println!("{:?}", opt);
println!("{opt:?}");
}

View file

@ -11,5 +11,5 @@ pub struct Opt {
fn main() {
let opt = Opt::parse();
println!("{:?}", opt);
println!("{opt:?}");
}

View file

@ -25,5 +25,5 @@ pub struct Opt {
fn main() {
let opt = Opt::parse();
println!("{:?}", opt);
println!("{opt:?}");
}

View file

@ -17,5 +17,5 @@ struct Opt {
fn main() {
let opt = Opt::parse();
println!("{:?}", opt);
println!("{opt:?}");
}

View file

@ -30,5 +30,5 @@ enum Command {
fn main() {
let opt = MakeCookie::parse();
println!("{:?}", opt);
println!("{opt:?}");
}

View file

@ -30,5 +30,5 @@ enum Command {
fn main() {
let opt = MakeCookie::parse();
println!("{:?}", opt);
println!("{opt:?}");
}

View file

@ -30,5 +30,5 @@ enum Command {
fn main() {
let opt = MakeCookie::parse();
println!("{:?}", opt);
println!("{opt:?}");
}

View file

@ -30,5 +30,5 @@ enum Command {
fn main() {
let opt = MakeCookie::parse();
println!("{:?}", opt);
println!("{opt:?}");
}

View file

@ -14,5 +14,5 @@ struct Opt(u32);
fn main() {
let opt = Opt::parse();
println!("{:?}", opt);
println!("{opt:?}");
}