updated formatting options

This commit is contained in:
Lynne Megido 2021-11-06 01:30:34 +10:00
parent 855211f458
commit 28aa3ad783
Signed by: lynnesbian
GPG Key ID: F0A184B5213D9F90
5 changed files with 14 additions and 56 deletions

View File

@ -7,3 +7,5 @@ hard_tabs = true
tab_spaces = 2 tab_spaces = 2
newline_style = "Unix" newline_style = "Unix"
group_imports = "StdExternalCrate" group_imports = "StdExternalCrate"
array_width = 100
fn_call_width = 80

View File

@ -209,11 +209,7 @@ pub fn scan_directory(
// TODO: is there a way to just say `map_or(x, |y| y).thing()` instead of `map_or(x.thing(), |y| y.thing())`? // TODO: is there a way to just say `map_or(x, |y| y).thing()` instead of `map_or(x.thing(), |y| y.thing())`?
// i don't care whether i'm returning a walkdir error or an io error, i just care about whether or not it // i don't care whether i'm returning a walkdir error or an io error, i just care about whether or not it
// implements ToString (which they both do). map_or doesn't work on trait objects though :( // implements ToString (which they both do). map_or doesn't work on trait objects though :(
error!( error!("{}: {}", path, err.io_error().map_or(err.to_string(), |e| e.to_string()));
"{}: {}",
path,
err.io_error().map_or(err.to_string(), |e| e.to_string())
);
return None; return None;
} }
e.ok() e.ok()
@ -353,23 +349,14 @@ pub fn mime_extension_lookup(essence: String) -> Option<Vec<String>> {
} else if essence == "application/zip" { } else if essence == "application/zip" {
// neither xdg-mime nor infer seem to be able to detect office XML files properly... // neither xdg-mime nor infer seem to be able to detect office XML files properly...
[ [
vec![ vec![String::from("zip"), String::from("docx"), String::from("xlsx"), String::from("pptx")],
String::from("zip"),
String::from("docx"),
String::from("xlsx"),
String::from("pptx"),
],
possible_exts, possible_exts,
] ]
.concat() .concat()
} else if essence == "application/x-ms-dos-executable" { } else if essence == "application/x-ms-dos-executable" {
// .dll, .exe, and .scr files are given the same mime type... but you definitely don't want to rename one to the // .dll, .exe, and .scr files are given the same mime type... but you definitely don't want to rename one to the
// other! // other!
[ [vec![String::from("dll"), String::from("exe"), String::from("scr")], possible_exts].concat()
vec![String::from("dll"), String::from("exe"), String::from("scr")],
possible_exts,
]
.concat()
} else { } else {
possible_exts possible_exts
}) })
@ -381,6 +368,8 @@ pub fn mime_extension_lookup(essence: String) -> Option<Vec<String>> {
cache.insert(essence, exts.clone()); cache.insert(essence, exts.clone());
exts exts
} else { } else {
// this should only ever happen if cache.insert() hangs on another thread; i.e., close enough to "never" that
// marking this as unreachable should be fine
unreachable!() unreachable!()
} }
} }

View File

@ -179,14 +179,7 @@ impl FormatSteps for Shell {
fn no_known_extension<W: Write>(&self, f: &mut W, path: &Path) -> io::Result<()> { fn no_known_extension<W: Write>(&self, f: &mut W, path: &Path) -> io::Result<()> {
smart_write( smart_write(
f, f,
writablesln![ writablesln!["cat <<- '???'", Newline, "No known extension for ", path, Newline, "???"],
"cat <<- '???'",
Newline,
"No known extension for ",
path,
Newline,
"???"
],
) )
} }
@ -199,10 +192,7 @@ impl FormatSteps for Shell {
} }
fn header<W: Write>(&self, f: &mut W) -> io::Result<()> { fn header<W: Write>(&self, f: &mut W) -> io::Result<()> {
smart_write( smart_write(f, writablesln!["#!/usr/bin/env sh", Newline, "# ", (generated_by().as_str())])?;
f,
writablesln!["#!/usr/bin/env sh", Newline, "# ", (generated_by().as_str())],
)?;
if let Ok(working_directory) = std::env::current_dir() { if let Ok(working_directory) = std::env::current_dir() {
smart_write(f, writablesln!["# Run from ", (working_directory.as_path())])?; smart_write(f, writablesln!["# Run from ", (working_directory.as_path())])?;
@ -232,26 +222,14 @@ impl FormatSteps for PowerShell {
// there doesn't seem to be a way to rename the file, prompting only if the target already exists. // there doesn't seem to be a way to rename the file, prompting only if the target already exists.
smart_write( smart_write(
f, f,
writablesln![ writablesln!["Rename-Item -Verbose -Path ", from, " -NewName ", (to.file_name().unwrap())],
"Rename-Item -Verbose -Path ",
from,
" -NewName ",
(to.file_name().unwrap())
],
) )
} }
fn no_known_extension<W: Write>(&self, f: &mut W, path: &Path) -> io::Result<()> { fn no_known_extension<W: Write>(&self, f: &mut W, path: &Path) -> io::Result<()> {
smart_write( smart_write(
f, f,
writablesln![ writablesln!["Write-Output @'", Newline, "No known extension for ", path, Newline, "'@"],
"Write-Output @'",
Newline,
"No known extension for ",
path,
Newline,
"'@"
],
) )
} }

View File

@ -319,12 +319,7 @@ impl ExtensionSet {
Self::Images => mime_guess::get_mime_extensions_str("image/*").unwrap().to_vec(), Self::Images => mime_guess::get_mime_extensions_str("image/*").unwrap().to_vec(),
Self::Audio => mime_guess::get_mime_extensions_str("audio/*").unwrap().to_vec(), Self::Audio => mime_guess::get_mime_extensions_str("audio/*").unwrap().to_vec(),
Self::Video => mime_guess::get_mime_extensions_str("video/*").unwrap().to_vec(), Self::Video => mime_guess::get_mime_extensions_str("video/*").unwrap().to_vec(),
Self::Media => [ Self::Media => [Self::Images.extensions(), Self::Audio.extensions(), Self::Video.extensions()].concat(),
Self::Images.extensions(),
Self::Audio.extensions(),
Self::Video.extensions(),
]
.concat(),
Self::Documents => vec![ Self::Documents => vec![
"pdf", "doc", "docx", "ppt", "pptx", "xls", "xlsx", "csv", "tsv", "odt", "ods", "odp", "oda", "rtf", "ps", "pdf", "doc", "docx", "ppt", "pptx", "xls", "xlsx", "csv", "tsv", "odt", "ods", "odp", "oda", "rtf", "ps",
"pages", "key", "numbers", "pages", "key", "numbers",

View File

@ -141,10 +141,7 @@ fn simple_directory() {
// 3. ensure the recommended extension for "wrong.jpg" is "png" // 3. ensure the recommended extension for "wrong.jpg" is "png"
assert_eq!(&result.recommended_extension().unwrap(), &String::from("png")); assert_eq!(&result.recommended_extension().unwrap(), &String::from("png"));
// 4. ensure the recommended filename for "wrong.jpg" is "wrong.png" // 4. ensure the recommended filename for "wrong.jpg" is "wrong.png"
assert_eq!( assert_eq!(result.recommended_path().unwrap().file_name(), Some(OsStr::new("wrong.png")));
result.recommended_path().unwrap().file_name(),
Some(OsStr::new("wrong.png"))
);
continue; continue;
} }
@ -470,10 +467,7 @@ fn verbosity() {
#[test] #[test]
/// Ensures `os_name()`'s output is the same as [`std::env::consts::OS`], capitalisation notwithstanding /// Ensures `os_name()`'s output is the same as [`std::env::consts::OS`], capitalisation notwithstanding
fn validate_os_name() { fn validate_os_name() {
assert_eq!( assert_eq!(fif::utils::os_name().to_lowercase(), std::env::consts::OS.to_lowercase());
fif::utils::os_name().to_lowercase(),
std::env::consts::OS.to_lowercase()
);
} }
#[test] #[test]