style: Make clippy happy

This commit is contained in:
Ed Page 2024-09-26 21:20:17 -05:00
parent 6556ad7e3b
commit cbcbaa3ad4
14 changed files with 28 additions and 38 deletions

View file

@ -109,7 +109,7 @@ impl<'cmd> Usage<'cmd> {
{
self.write_arg_usage(styled, &[], true);
styled.trim_end();
let _ = write!(styled, "{}", USAGE_SEP);
let _ = write!(styled, "{USAGE_SEP}");
}
let mut cmd = self.cmd.clone();
cmd.build();
@ -120,7 +120,7 @@ impl<'cmd> Usage<'cmd> {
{
if i != 0 {
styled.trim_end();
let _ = write!(styled, "{}", USAGE_SEP);
let _ = write!(styled, "{USAGE_SEP}");
}
Usage::new(sub).write_usage_no_title(styled, &[]);
}
@ -183,7 +183,7 @@ impl<'cmd> Usage<'cmd> {
|| self.cmd.is_args_conflicts_with_subcommands_set()
{
styled.trim_end();
let _ = write!(styled, "{}", USAGE_SEP);
let _ = write!(styled, "{USAGE_SEP}");
if self.cmd.is_args_conflicts_with_subcommands_set() {
let bin_name = self.cmd.get_usage_name_fallback();
// Short-circuit full usage creation since no args will be relevant

View file

@ -16,7 +16,7 @@ fn main() {
return;
}
println!("{:?}", matches);
println!("{matches:?}");
}
fn print_completions<G: Generator>(gen: G, cmd: &mut clap::Command) {

View file

@ -196,7 +196,7 @@ fn option_details_for_path(cmd: &Command, path: &str) -> String {
if let Some(copt) = compopt {
v.extend([
r#"if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then"#.to_string(),
format!(" {}", copt),
format!(" {copt}"),
"fi".to_string(),
]);
}
@ -229,7 +229,7 @@ fn option_details_for_path(cmd: &Command, path: &str) -> String {
if let Some(copt) = compopt {
v.extend([
r#"if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then"#.to_string(),
format!(" {}", copt),
format!(" {copt}"),
"fi".to_string(),
]);
}

View file

@ -72,7 +72,7 @@ fn generate_inner(p: &Command, previous_command_name: &str) -> String {
} else {
p.get_name_and_visible_aliases()
.into_iter()
.map(|name| format!("{};{}", previous_command_name, name))
.map(|name| format!("{previous_command_name};{name}"))
.collect()
};

View file

@ -178,7 +178,7 @@ fn gen_fish_inner(
for subcommand_name in subcommand.get_name_and_visible_aliases() {
let mut template = basic_template.clone();
template.push_str(format!(" -a \"{}\"", subcommand_name).as_str());
template.push_str(format!(" -a \"{subcommand_name}\"").as_str());
if let Some(data) = subcommand.get_about() {
template.push_str(format!(" -d '{}'", escape_help(data)).as_str());

View file

@ -77,7 +77,7 @@ fn generate_inner(p: &Command, previous_command_name: &str) -> String {
} else {
p.get_name_and_visible_aliases()
.into_iter()
.map(|name| format!("{};{}", previous_command_name, name))
.map(|name| format!("{previous_command_name};{name}"))
.collect()
};
@ -106,10 +106,9 @@ fn generate_inner(p: &Command, previous_command_name: &str) -> String {
for command_name in &command_names {
subcommands_cases.push_str(&format!(
r"
'{}' {{{}
'{command_name}' {{{completions}
break
}}",
command_name, completions
}}"
));
}

View file

@ -198,15 +198,15 @@ fn complete_arg(
completions.extend(
complete_arg_value(value.to_str().ok_or(value), arg, current_dir)
.into_iter()
.map(|comp| comp.add_prefix(format!("--{}=", flag))),
.map(|comp| comp.add_prefix(format!("--{flag}="))),
);
}
} else {
completions.extend(longs_and_visible_aliases(cmd).into_iter().filter(
|comp| comp.get_value().starts_with(format!("--{}", flag).as_str()),
|comp| comp.get_value().starts_with(format!("--{flag}").as_str()),
));
completions.extend(hidden_longs_aliases(cmd).into_iter().filter(|comp| {
comp.get_value().starts_with(format!("--{}", flag).as_str())
comp.get_value().starts_with(format!("--{flag}").as_str())
}));
}
}
@ -428,9 +428,9 @@ fn longs_and_visible_aliases(p: &clap::Command) -> Vec<CompletionCandidate> {
p.get_arguments()
.filter_map(|a| {
a.get_long_and_visible_aliases().map(|longs| {
longs.into_iter().map(|s| {
populate_arg_candidate(CompletionCandidate::new(format!("--{}", s)), a)
})
longs
.into_iter()
.map(|s| populate_arg_candidate(CompletionCandidate::new(format!("--{s}")), a))
})
})
.flatten()
@ -445,8 +445,7 @@ fn hidden_longs_aliases(p: &clap::Command) -> Vec<CompletionCandidate> {
.filter_map(|a| {
a.get_aliases().map(|longs| {
longs.into_iter().map(|s| {
populate_arg_candidate(CompletionCandidate::new(format!("--{}", s)), a)
.hide(true)
populate_arg_candidate(CompletionCandidate::new(format!("--{s}")), a).hide(true)
})
})
})

View file

@ -260,7 +260,7 @@ impl<'s, F: FnOnce() -> clap::Command> CompleteEnv<'s, F> {
completer.to_owned()
} else {
let mut completer = std::path::PathBuf::from(completer);
if let Some(current_dir) = current_dir.as_deref() {
if let Some(current_dir) = current_dir {
if 1 < completer.components().count() {
completer = current_dir.join(completer);
}

View file

@ -121,7 +121,7 @@ impl FromStr for CompType {
"33" => Ok(Self::Alternatives),
"64" => Ok(Self::Unmodified),
"37" => Ok(Self::Menu),
_ => Err(format!("unsupported COMP_TYPE `{}`", s)),
_ => Err(format!("unsupported COMP_TYPE `{s}`")),
}
}
}

View file

@ -193,8 +193,7 @@ fn complete() {
&& actual.contains("b_file")
&& actual.contains("c_dir")
&& actual.contains("d_dir"),
"Actual output:\n{}",
actual
"Actual output:\n{actual}"
);
let input = format!(
@ -207,8 +206,7 @@ fn complete() {
&& !actual.contains("b_file")
&& actual.contains("c_dir")
&& actual.contains("d_dir"),
"Actual output:\n{}",
actual
"Actual output:\n{actual}"
);
}

View file

@ -429,8 +429,7 @@ pub(crate) fn has_command(command: &str) -> bool {
// CI is expected to support all of the commands
if is_ci() && cfg!(target_os = "linux") {
panic!(
"expected command `{}` to be somewhere in PATH: {}",
command, e
"expected command `{command}` to be somewhere in PATH: {e}"
);
}
return false;
@ -450,8 +449,7 @@ pub(crate) fn has_command(command: &str) -> bool {
let stdout = String::from_utf8_lossy(&output.stdout);
println!(
"$ {command} --version
{}",
stdout
{stdout}"
);
if cfg!(target_os = "macos") && stdout.starts_with("GNU bash, version 3") {
return false;

View file

@ -7,7 +7,7 @@ fn main() {
let mut cmd = cli();
generate(Nushell, &mut cmd, "test", &mut std::io::stdout());
} else {
println!("{:?}", matches);
println!("{matches:?}");
}
}

View file

@ -375,10 +375,7 @@ pub(crate) fn has_command(command: &str) -> bool {
Err(e) => {
// CI is expected to support all of the commands
if is_ci() && cfg!(target_os = "linux") {
panic!(
"expected command `{}` to be somewhere in PATH: {}",
command, e
);
panic!("expected command `{command}` to be somewhere in PATH: {e}");
}
return false;
}
@ -397,8 +394,7 @@ pub(crate) fn has_command(command: &str) -> bool {
let stdout = String::from_utf8_lossy(&output.stdout);
println!(
"$ {command} --version
{}",
stdout
{stdout}"
);
if cfg!(target_os = "macos") && stdout.starts_with("GNU bash, version 3") {
return false;

View file

@ -11,7 +11,7 @@ pub(crate) fn subcommand_heading(cmd: &clap::Command) -> &str {
pub(crate) fn about(roff: &mut Roff, cmd: &clap::Command) {
let name = cmd.get_display_name().unwrap_or_else(|| cmd.get_name());
let s = match cmd.get_about().or_else(|| cmd.get_long_about()) {
Some(about) => format!("{} - {}", name, about),
Some(about) => format!("{name} - {about}"),
None => name.to_owned(),
};
roff.text([roman(s)]);