Skip to content

Commit

Permalink
Merge pull request #5751 from epage/update
Browse files Browse the repository at this point in the history
chore: Update from _rust template
  • Loading branch information
epage authored Sep 27, 2024
2 parents 8a35018 + cbcbaa3 commit a6286cf
Show file tree
Hide file tree
Showing 16 changed files with 31 additions and 38 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- uses: pre-commit/[email protected]
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ string_lit_as_bytes = "warn"
# string_to_string = "warn"
todo = "warn"
trait_duplication_in_bounds = "warn"
uninlined_format_args = "warn"
verbose_file_reads = "warn"
# wildcard_imports = "warn"
zero_sized_map_values = "warn"
Expand Down
6 changes: 3 additions & 3 deletions clap_builder/src/output/usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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, &[]);
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion clap_complete/examples/exhaustive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn main() {
return;
}

println!("{:?}", matches);
println!("{matches:?}");
}

fn print_completions<G: Generator>(gen: G, cmd: &mut clap::Command) {
Expand Down
4 changes: 2 additions & 2 deletions clap_complete/src/aot/shells/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
]);
}
Expand Down Expand Up @@ -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(),
]);
}
Expand Down
2 changes: 1 addition & 1 deletion clap_complete/src/aot/shells/elvish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};

Expand Down
2 changes: 1 addition & 1 deletion clap_complete/src/aot/shells/fish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
7 changes: 3 additions & 4 deletions clap_complete/src/aot/shells/powershell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};

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

Expand Down
15 changes: 7 additions & 8 deletions clap_complete/src/engine/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}));
}
}
Expand Down Expand Up @@ -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()
Expand All @@ -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)
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion clap_complete/src/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion clap_complete/src/env/shells.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}`")),
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions clap_complete/tests/testsuite/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand All @@ -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}"
);
}

Expand Down
6 changes: 2 additions & 4 deletions clap_complete/tests/testsuite/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion clap_complete_nushell/examples/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn main() {
let mut cmd = cli();
generate(Nushell, &mut cmd, "test", &mut std::io::stdout());
} else {
println!("{:?}", matches);
println!("{matches:?}");
}
}

Expand Down
8 changes: 2 additions & 6 deletions clap_complete_nushell/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion clap_mangen/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]);
Expand Down

0 comments on commit a6286cf

Please sign in to comment.