resolved clippy warnings
This commit is contained in:
parent
ae45871a57
commit
1568bcb094
|
@ -1,14 +1,14 @@
|
|||
pub const TARGET_URL: &str =
|
||||
"https://github.com/Vomitblood/pokesprite/archive/refs/heads/master.zip";
|
||||
|
||||
pub const DATA_DIRECTORY: once_cell::sync::Lazy<std::path::PathBuf> =
|
||||
pub static DATA_DIRECTORY: once_cell::sync::Lazy<std::path::PathBuf> =
|
||||
once_cell::sync::Lazy::new(|| {
|
||||
dirs::data_dir()
|
||||
.map(|dir| dir.join("rustmon"))
|
||||
.expect("Data directory not found")
|
||||
});
|
||||
|
||||
pub const CACHE_DIRECTORY: once_cell::sync::Lazy<std::path::PathBuf> =
|
||||
pub static CACHE_DIRECTORY: once_cell::sync::Lazy<std::path::PathBuf> =
|
||||
once_cell::sync::Lazy::new(|| {
|
||||
dirs::cache_dir()
|
||||
.map(|dir| dir.join("rustmon"))
|
||||
|
|
34
src/fetch.rs
34
src/fetch.rs
|
@ -96,7 +96,7 @@ fn create_working_directory() -> std::io::Result<()> {
|
|||
// create intermediate directories also
|
||||
std::fs::create_dir(&*crate::constants::CACHE_DIRECTORY)?;
|
||||
println!("Created working directory");
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn create_output_directory(output_directory_path: &std::path::Path) -> std::io::Result<()> {
|
||||
|
@ -106,7 +106,7 @@ fn create_output_directory(output_directory_path: &std::path::Path) -> std::io::
|
|||
);
|
||||
std::fs::create_dir_all(output_directory_path)?;
|
||||
println!("Created output directory");
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn fetch_pokemon_json() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
@ -193,7 +193,7 @@ fn read_pokemon_file(
|
|||
// deserialize the into pokemoncollection
|
||||
let collection = serde_json::from_reader(reader)?;
|
||||
|
||||
return Ok(collection);
|
||||
Ok(collection)
|
||||
}
|
||||
|
||||
fn transform_pokemon_data(
|
||||
|
@ -240,7 +240,7 @@ fn transform_pokemon_data(
|
|||
.cmp(&b.pokedex.parse::<u32>().unwrap_or(0))
|
||||
});
|
||||
|
||||
return processed_pokemons;
|
||||
processed_pokemons
|
||||
}
|
||||
|
||||
fn fetch_colorscripts_archive(target_url: &str) -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
@ -333,10 +333,10 @@ fn extract_colorscripts_archive() -> zip::result::ZipResult<()> {
|
|||
if !file.name().ends_with('/') {
|
||||
if let Some(p) = outpath.parent() {
|
||||
if !p.exists() {
|
||||
std::fs::create_dir_all(&p)?;
|
||||
std::fs::create_dir_all(p)?;
|
||||
}
|
||||
}
|
||||
let mut outfile = std::fs::File::create(&outpath)?;
|
||||
let mut outfile = std::fs::File::create(outpath)?;
|
||||
std::io::copy(&mut file, &mut outfile)?;
|
||||
};
|
||||
};
|
||||
|
@ -344,7 +344,7 @@ fn extract_colorscripts_archive() -> zip::result::ZipResult<()> {
|
|||
|
||||
println!("Extracted colorscripts archive");
|
||||
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn crop_all_images_in_directory() -> std::io::Result<()> {
|
||||
|
@ -368,9 +368,9 @@ fn crop_all_images_in_directory() -> std::io::Result<()> {
|
|||
.join("cropped_images")
|
||||
.join(subdirectory);
|
||||
|
||||
std::fs::create_dir_all(&output_subdirectory_path)?;
|
||||
std::fs::create_dir_all(output_subdirectory_path)?;
|
||||
|
||||
for entry in std::fs::read_dir(&input_subdirectory_path)? {
|
||||
for entry in std::fs::read_dir(input_subdirectory_path)? {
|
||||
let entry = entry?;
|
||||
let path = entry.path();
|
||||
|
||||
|
@ -381,7 +381,7 @@ fn crop_all_images_in_directory() -> std::io::Result<()> {
|
|||
|
||||
println!("Cropped images");
|
||||
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn crop_to_content(
|
||||
|
@ -436,7 +436,7 @@ fn crop_to_content(
|
|||
// write the cropped image
|
||||
cropped_img.save(output_path)?;
|
||||
|
||||
return Ok(cropped_img);
|
||||
Ok(cropped_img)
|
||||
}
|
||||
|
||||
fn convert_images_to_ascii(
|
||||
|
@ -458,7 +458,7 @@ fn convert_images_to_ascii(
|
|||
|
||||
std::fs::create_dir_all(&output_subdirectory_path)?;
|
||||
|
||||
for entry in std::fs::read_dir(&input_subdirectory_path)? {
|
||||
for entry in std::fs::read_dir(input_subdirectory_path)? {
|
||||
let entry = entry?;
|
||||
let path = entry.path();
|
||||
|
||||
|
@ -471,7 +471,7 @@ fn convert_images_to_ascii(
|
|||
};
|
||||
|
||||
// print for fun
|
||||
if verbose == true {
|
||||
if verbose {
|
||||
println!("{}", ascii_art);
|
||||
};
|
||||
|
||||
|
@ -485,7 +485,7 @@ fn convert_images_to_ascii(
|
|||
|
||||
println!("Converted images to ASCII");
|
||||
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn convert_image_to_unicode_small(img: &image::DynamicImage) -> String {
|
||||
|
@ -520,7 +520,7 @@ fn convert_image_to_unicode_small(img: &image::DynamicImage) -> String {
|
|||
unicode_sprite.push('\n'); // New line for each row, plus reset might be added here too if colors extend beyond.
|
||||
}
|
||||
|
||||
return unicode_sprite;
|
||||
unicode_sprite
|
||||
}
|
||||
|
||||
fn convert_image_to_unicode_big(img: &image::DynamicImage) -> String {
|
||||
|
@ -541,7 +541,7 @@ fn convert_image_to_unicode_big(img: &image::DynamicImage) -> String {
|
|||
unicode_sprite.push('\n');
|
||||
}
|
||||
|
||||
return unicode_sprite;
|
||||
unicode_sprite
|
||||
}
|
||||
|
||||
fn get_color_escape_code(pixel: image::Rgba<u8>, background: bool) -> String {
|
||||
|
@ -569,5 +569,5 @@ fn cleanup() -> std::io::Result<()> {
|
|||
|
||||
println!("Cleaned up");
|
||||
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ pub fn print_pokemon_list() -> Result<(), serde_json::Error> {
|
|||
|
||||
println!("\nHint: Having trouble finding a Pokemon? Pass in --help to see tips!");
|
||||
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn print_pokemon_forms(pokemon_name: &str) -> std::io::Result<()> {
|
||||
|
@ -47,5 +47,5 @@ pub fn print_pokemon_forms(pokemon_name: &str) -> std::io::Result<()> {
|
|||
println!("\nHint: Pass in `--form` when using subcommand `print` to see the specific form of a Pokemon!");
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ fn argument_parser() -> clap::ArgMatches {
|
|||
.help("eXtract the colorscripts archive to a custom location")
|
||||
.short('x')
|
||||
.long("extract-destination")
|
||||
.default_value(&*rustmon::constants::DATA_DIRECTORY.to_str().unwrap()),
|
||||
.default_value(rustmon::constants::DATA_DIRECTORY.to_str().unwrap()),
|
||||
)
|
||||
// fetch/verbose
|
||||
.arg(
|
||||
|
|
36
src/print.rs
36
src/print.rs
|
@ -14,10 +14,10 @@ pub fn print(
|
|||
spacing: u8,
|
||||
) {
|
||||
// decide which function to call
|
||||
if big == false
|
||||
if !big
|
||||
// uber fast random
|
||||
&& forms.len() == 1
|
||||
&& hide_name == false
|
||||
&& !hide_name
|
||||
&& (names.len() == 1 && pokedexes.len() == 1)
|
||||
&& shiny_rate == 0.0
|
||||
&& forms[0] == "regular"
|
||||
|
@ -67,7 +67,7 @@ fn random_lite() -> std::io::Result<()> {
|
|||
let path = crate::constants::DATA_DIRECTORY.join("colorscripts/small/regular/");
|
||||
let mut files: Vec<std::path::PathBuf> = Vec::new();
|
||||
|
||||
for entry in std::fs::read_dir(&path)? {
|
||||
for entry in std::fs::read_dir(path)? {
|
||||
let dir_entry = entry?;
|
||||
files.push(dir_entry.path());
|
||||
}
|
||||
|
@ -117,13 +117,13 @@ fn get_pokemon_data(pokedex_number: u16) -> crate::structs::Pokemon {
|
|||
pokemons.get(pokedex_number as usize - 1).unwrap().clone();
|
||||
|
||||
// return the data
|
||||
return pokemon_data;
|
||||
pokemon_data
|
||||
}
|
||||
|
||||
fn find_pokedex_by_pokemon(pokemon_name: &str) -> Result<String, Box<dyn std::error::Error>> {
|
||||
// handle random
|
||||
if pokemon_name == "random" {
|
||||
return Ok("0".to_string());
|
||||
Ok("0".to_string())
|
||||
} else {
|
||||
// read the file
|
||||
let mut file = std::fs::File::open(crate::constants::DATA_DIRECTORY.join("pokemon.json"))?;
|
||||
|
@ -142,7 +142,7 @@ fn find_pokedex_by_pokemon(pokemon_name: &str) -> Result<String, Box<dyn std::er
|
|||
}
|
||||
|
||||
// if not found the return an error
|
||||
return Err(format!("Pokemon {} not found", pokemon_name).into());
|
||||
Err(format!("Pokemon {} not found", pokemon_name).into())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,7 +151,7 @@ fn is_shiny(shiny_rate: f32) -> bool {
|
|||
let random_number = rand::random::<f32>();
|
||||
|
||||
// if the random number is less than the shiny rate then return true
|
||||
return random_number < shiny_rate;
|
||||
random_number < shiny_rate
|
||||
}
|
||||
|
||||
fn process_pokedexes_list(pokedexes: Vec<u16>) -> Vec<u16> {
|
||||
|
@ -164,10 +164,10 @@ fn process_pokedexes_list(pokedexes: Vec<u16>) -> Vec<u16> {
|
|||
}
|
||||
}
|
||||
|
||||
return pokedexes_processed;
|
||||
pokedexes_processed
|
||||
}
|
||||
|
||||
fn process_forms_list(pokedexes: &Vec<u16>, forms: Vec<&String>) -> Vec<String> {
|
||||
fn process_forms_list(pokedexes: &[u16], forms: Vec<&String>) -> Vec<String> {
|
||||
let mut forms_processed: Vec<String> = forms.iter().map(|s| s.to_string()).collect();
|
||||
|
||||
// ensure forms_processed has the same length as pokedexes
|
||||
|
@ -188,7 +188,7 @@ fn process_forms_list(pokedexes: &Vec<u16>, forms: Vec<&String>) -> Vec<String>
|
|||
}
|
||||
}
|
||||
|
||||
return forms_processed;
|
||||
forms_processed
|
||||
}
|
||||
|
||||
fn slug_generator(big: bool, form: String, name: String, shiny_rate: f32) -> std::path::PathBuf {
|
||||
|
@ -221,17 +221,17 @@ fn slug_generator(big: bool, form: String, name: String, shiny_rate: f32) -> std
|
|||
// construct the path using PathBuf
|
||||
let mut path = std::path::PathBuf::new();
|
||||
path.push(crate::constants::DATA_DIRECTORY.join("colorscripts"));
|
||||
path.push(format!("{}", big));
|
||||
path.push(&big);
|
||||
path.push(shiny_directory);
|
||||
path.push(format!("{}{}", name, form));
|
||||
|
||||
return path;
|
||||
path
|
||||
}
|
||||
|
||||
fn generate_slug_list(
|
||||
big: bool,
|
||||
forms: Vec<String>,
|
||||
pokedexes: &Vec<u16>,
|
||||
pokedexes: &[u16],
|
||||
shiny_rate: f32,
|
||||
) -> Vec<std::path::PathBuf> {
|
||||
let mut slugs: Vec<std::path::PathBuf> = Vec::new();
|
||||
|
@ -245,10 +245,10 @@ fn generate_slug_list(
|
|||
slugs.push(slug);
|
||||
}
|
||||
|
||||
return slugs;
|
||||
slugs
|
||||
}
|
||||
|
||||
fn print_name(paths: &Vec<std::path::PathBuf>) {
|
||||
fn print_name(paths: &[std::path::PathBuf]) {
|
||||
let last_parts: Vec<&str> = paths
|
||||
.iter()
|
||||
.filter_map(|path| path.file_name())
|
||||
|
@ -259,13 +259,13 @@ fn print_name(paths: &Vec<std::path::PathBuf>) {
|
|||
println!("{}", output);
|
||||
}
|
||||
|
||||
fn print_colorscripts(paths: &Vec<std::path::PathBuf>, spacing: u8) -> std::io::Result<()> {
|
||||
fn print_colorscripts(paths: &[std::path::PathBuf], spacing: u8) -> std::io::Result<()> {
|
||||
// open all files and create BufReaders
|
||||
let mut readers: Vec<_> = paths
|
||||
.iter()
|
||||
.map(|path| std::fs::File::open(path))
|
||||
.map(std::fs::File::open)
|
||||
.filter_map(|result| result.ok())
|
||||
.map(|file| std::io::BufReader::new(file))
|
||||
.map(std::io::BufReader::new)
|
||||
.collect();
|
||||
|
||||
// create a string for spacing
|
||||
|
|
|
@ -36,13 +36,8 @@ fn validate_pokemon_json() -> Result<(), Box<dyn std::error::Error>> {
|
|||
serde_json::from_reader(reader);
|
||||
|
||||
match pokemon_data {
|
||||
Ok(_) => return Ok(()),
|
||||
Err(_) => {
|
||||
return Err(format!(
|
||||
"JSON structure is not correct. Please run the `fetch` subcommand."
|
||||
)
|
||||
.into())
|
||||
}
|
||||
Ok(_) => Ok(()),
|
||||
Err(_) => Err("JSON structure is not correct. Please run the `fetch` subcommand.".into()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,11 +49,9 @@ fn validate_colorscripts_directory() -> Result<(), String> {
|
|||
for subdirectory in subdirectories.iter() {
|
||||
let path = base_path.join(subdirectory);
|
||||
if !path.exists() {
|
||||
return Err(format!(
|
||||
"Directory does not exist. Please run the `fetch` subcommand."
|
||||
));
|
||||
return Err("Directory does not exist. Please run the `fetch` subcommand.".into());
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue