clippy, format
This commit is contained in:
parent
4469104ac1
commit
5017854dd3
5 changed files with 17 additions and 22 deletions
|
@ -90,7 +90,7 @@ pub fn smart_write<W: Write>(f: &mut W, writeables: &[Writable]) -> io::Result<(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Writable::String(s) => write!(f, "{}", s)?,
|
Writable::String(s) => write!(f, "{s}")?,
|
||||||
Writable::Path(path) => {
|
Writable::Path(path) => {
|
||||||
if let Some(path_str) = path.to_str() {
|
if let Some(path_str) = path.to_str() {
|
||||||
let escaped = escape(path_str);
|
let escaped = escape(path_str);
|
||||||
|
@ -98,9 +98,9 @@ pub fn smart_write<W: Write>(f: &mut W, writeables: &[Writable]) -> io::Result<(
|
||||||
// the escaped string is the same as the input - this will occur for inputs like "file.txt" which don't
|
// the escaped string is the same as the input - this will occur for inputs like "file.txt" which don't
|
||||||
// need to be escaped. however, it's Best Practice™ to escape such strings anyway, so we prefix/suffix the
|
// need to be escaped. however, it's Best Practice™ to escape such strings anyway, so we prefix/suffix the
|
||||||
// escaped string with single quotes.
|
// escaped string with single quotes.
|
||||||
write!(f, "'{}'", escaped)?;
|
write!(f, "'{escaped}'")?;
|
||||||
} else {
|
} else {
|
||||||
write!(f, "{}", escaped)?;
|
write!(f, "{escaped}")?;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
write!(f, "'")?;
|
write!(f, "'")?;
|
||||||
|
|
|
@ -132,7 +132,7 @@ fn main() {
|
||||||
if args.fix {
|
if args.fix {
|
||||||
fn ask(message: &str) -> bool {
|
fn ask(message: &str) -> bool {
|
||||||
let mut buf = String::with_capacity(1);
|
let mut buf = String::with_capacity(1);
|
||||||
print!("{} [y/N] ", message);
|
print!("{message} [y/N] ");
|
||||||
|
|
||||||
// flush stdout to ensure message is displayed
|
// flush stdout to ensure message is displayed
|
||||||
stdout().flush().expect("Failed to flush stdout");
|
stdout().flush().expect("Failed to flush stdout");
|
||||||
|
@ -166,7 +166,7 @@ fn main() {
|
||||||
} else if prompt == Prompt::Error || ask(&format!("Rename {:#?} to {:#?}?", &f.file, &rename_to)) {
|
} else if prompt == Prompt::Error || ask(&format!("Rename {:#?} to {:#?}?", &f.file, &rename_to)) {
|
||||||
// handles: --prompt error --overwrite, --prompt always --overwrite [y]
|
// handles: --prompt error --overwrite, --prompt always --overwrite [y]
|
||||||
// if the target exists, prompt before renaming; otherwise, just rename
|
// if the target exists, prompt before renaming; otherwise, just rename
|
||||||
!rename_to.exists() || ask(&format!("Destination {:#?} already exists, overwrite?", rename_to))
|
!rename_to.exists() || ask(&format!("Destination {rename_to:#?} already exists, overwrite?"))
|
||||||
} else {
|
} else {
|
||||||
// handles: --prompt always --overwrite [n]
|
// handles: --prompt always --overwrite [n]
|
||||||
// user was prompted and replied "no"
|
// user was prompted and replied "no"
|
||||||
|
@ -191,7 +191,7 @@ fn main() {
|
||||||
warn!("Couldn't rename {:#?} to {:#?}: {:#?}", f.file, rename_to, e);
|
warn!("Couldn't rename {:#?} to {:#?}: {:#?}", f.file, rename_to, e);
|
||||||
// if the user passed --prompt never, continue to the next file
|
// if the user passed --prompt never, continue to the next file
|
||||||
// otherwise, prompt user to retry move, retrying until the rename succeeds or they respond "N"
|
// otherwise, prompt user to retry move, retrying until the rename succeeds or they respond "N"
|
||||||
if prompt == Prompt::Never || !ask(&format!("Error while renaming file: {:#?}. Try again?", e)) {
|
if prompt == Prompt::Never || !ask(&format!("Error while renaming file: {e:#?}. Try again?")) {
|
||||||
failed += 1;
|
failed += 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ cfg_if! {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn open_document_check(buf: &[u8], kind: &str) -> bool {
|
fn open_document_check(buf: &[u8], kind: &str) -> bool {
|
||||||
let mime = format!("application/vnd.oasis.opendocument.{}", kind);
|
let mime = format!("application/vnd.oasis.opendocument.{kind}");
|
||||||
let mime = mime.as_bytes();
|
let mime = mime.as_bytes();
|
||||||
|
|
||||||
buf.len() > 38 + mime.len() && buf.starts_with(b"PK\x03\x04") && buf[38..mime.len() + 38] == mime[..]
|
buf.len() > 38 + mime.len() && buf.starts_with(b"PK\x03\x04") && buf[38..mime.len() + 38] == mime[..]
|
||||||
|
|
|
@ -7,7 +7,7 @@ use std::collections::BTreeSet;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use cfg_if::cfg_if;
|
use cfg_if::cfg_if;
|
||||||
use clap::{ValueEnum, Parser, ArgAction};
|
use clap::{ArgAction, Parser, ValueEnum};
|
||||||
|
|
||||||
use crate::utils::{CLAP_LONG_VERSION, CLAP_VERSION};
|
use crate::utils::{CLAP_LONG_VERSION, CLAP_VERSION};
|
||||||
use crate::String as StringType;
|
use crate::String as StringType;
|
||||||
|
|
|
@ -102,12 +102,11 @@ fn simple_directory() {
|
||||||
set_current_dir(dir.path()).expect("Failed to change directory.");
|
set_current_dir(dir.path()).expect("Failed to change directory.");
|
||||||
|
|
||||||
for (name, bytes) in &files {
|
for (name, bytes) in &files {
|
||||||
let mut file = File::create(dir.path().join(name))
|
let mut file = File::create(dir.path().join(name)).unwrap_or_else(|_| panic!("Failed to create file: {name}"));
|
||||||
.unwrap_or_else(|_| panic!("Failed to create file: {}", name));
|
|
||||||
|
|
||||||
file
|
file
|
||||||
.write_all(bytes)
|
.write_all(bytes)
|
||||||
.unwrap_or_else(|_| panic!("Failed to write to file: {}", name));
|
.unwrap_or_else(|_| panic!("Failed to write to file: {name}"));
|
||||||
drop(file);
|
drop(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,12 +279,12 @@ fn exclude_set_overrides_include_set() {
|
||||||
.iter()
|
.iter()
|
||||||
.chain(ExtensionSet::Video.extensions().iter())
|
.chain(ExtensionSet::Video.extensions().iter())
|
||||||
{
|
{
|
||||||
assert!(extensions.contains(&ext), "Extensions should contain {}!", ext);
|
assert!(extensions.contains(&ext), "Extensions should contain {ext}!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure all of images' extensions are excluded
|
// ensure all of images' extensions are excluded
|
||||||
for ext in ExtensionSet::Images.extensions() {
|
for ext in ExtensionSet::Images.extensions() {
|
||||||
assert!(!extensions.contains(&ext), "Extensions should not contain {}!", ext);
|
assert!(!extensions.contains(&ext), "Extensions should not contain {ext}!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,7 +315,7 @@ fn rejects_bad_args() {
|
||||||
|
|
||||||
for test in &tests {
|
for test in &tests {
|
||||||
// first, try testing the flags against the Parameters struct...
|
// first, try testing the flags against the Parameters struct...
|
||||||
assert!(Parameters::try_parse_from(test).is_err(), "Failed to reject {:?}", test);
|
assert!(Parameters::try_parse_from(test).is_err(), "Failed to reject {test:?}");
|
||||||
// ...then, make sure it actually works against the binary
|
// ...then, make sure it actually works against the binary
|
||||||
let mut cmd = Command::cargo_bin("fif").unwrap();
|
let mut cmd = Command::cargo_bin("fif").unwrap();
|
||||||
cmd.args(test).assert().failure();
|
cmd.args(test).assert().failure();
|
||||||
|
@ -359,8 +358,7 @@ fn check_version_output() {
|
||||||
let output = String::from_utf8(output).unwrap();
|
let output = String::from_utf8(output).unwrap();
|
||||||
assert!(
|
assert!(
|
||||||
Regex::new(r#"fif v([0-9]\.){2}[0-9]"#).unwrap().is_match(output.trim()),
|
Regex::new(r#"fif v([0-9]\.){2}[0-9]"#).unwrap().is_match(output.trim()),
|
||||||
"\"{}\" does not match the expected `-v` format!",
|
"\"{output}\" does not match the expected `-v` format!"
|
||||||
output
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// test `--version` matches the format of "fif x.y.z (OS, example backend, commit #1234abc)"
|
// test `--version` matches the format of "fif x.y.z (OS, example backend, commit #1234abc)"
|
||||||
|
@ -393,7 +391,7 @@ fn identify_random_bytes() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (mime, count) in &results {
|
for (mime, count) in &results {
|
||||||
println!("{}:\t{} counts", mime, count);
|
println!("{mime}:\t{count} counts");
|
||||||
}
|
}
|
||||||
println!("No type found:\t{} counts", 1000 - results.values().sum::<i32>());
|
println!("No type found:\t{} counts", 1000 - results.values().sum::<i32>());
|
||||||
}
|
}
|
||||||
|
@ -430,9 +428,7 @@ fn outputs_move_commands() {
|
||||||
// the output should contain a command like "mv -i misnamed_file.png misnamed_file.jpg"
|
// the output should contain a command like "mv -i misnamed_file.png misnamed_file.jpg"
|
||||||
assert!(
|
assert!(
|
||||||
contents.contains("misnamed_file.jpg") && contents.contains("misnamed_file.png"),
|
contents.contains("misnamed_file.jpg") && contents.contains("misnamed_file.png"),
|
||||||
"{} output doesn't contain move command!\n===\n{}",
|
"{format} output doesn't contain move command!\n===\n{contents}"
|
||||||
format,
|
|
||||||
contents
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -466,8 +462,7 @@ fn test_json() {
|
||||||
// the output should contain the file's MIME type
|
// the output should contain the file's MIME type
|
||||||
assert!(
|
assert!(
|
||||||
contents.contains(IMAGE_JPEG.essence_str()),
|
contents.contains(IMAGE_JPEG.essence_str()),
|
||||||
"JSON output doesn't contain move command!\n===\n{}",
|
"JSON output doesn't contain move command!\n===\n{contents}"
|
||||||
contents
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue