remove some comments and add some horrible error handling
This commit is contained in:
parent
1367f2d684
commit
d8d3311d25
|
@ -17,12 +17,9 @@ pub async fn download_image(cache_path: &String, image_url: String, file_name: S
|
|||
process::exit(1);
|
||||
}
|
||||
};
|
||||
// println!("{image:?}");
|
||||
|
||||
// println!("{}", yansi::Color::Magenta.paint(filename.clone()));
|
||||
// println!("{replaced}/{file_name}");
|
||||
|
||||
// println!("{}", yansi::Color::Magenta.paint(filepath.clone()));
|
||||
println!("{replaced}/{file_name}");
|
||||
let wrote = fs::write(format!("{replaced}/{file_name}"), image);
|
||||
if let Err(why) = wrote {
|
||||
eprintln!("cache::download_image: Couldn't save the image to `{replaced}/{file_name}`: {why:?}");
|
||||
|
|
28
src/lib.rs
28
src/lib.rs
|
@ -1,17 +1,33 @@
|
|||
pub mod cache;
|
||||
|
||||
use std::{fs, path::Path};
|
||||
use std::{fs, path::Path, process};
|
||||
|
||||
use scraper::{Html, Selector};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub fn get_home() -> String {
|
||||
match std::env::consts::OS {
|
||||
"linux" => std::env::var("HOME").expect("how is there not a $HOME"),
|
||||
"windows" => std::env::var("userprofile").expect("yell at me if this doesn't work please"),
|
||||
_ => std::env::var("HOME").expect(
|
||||
"if this doesn't work, you're probably on macos, which i literally cannot test on",
|
||||
),
|
||||
"linux" => match std::env::var("HOME") {
|
||||
Ok(var) => var,
|
||||
Err(why) => {
|
||||
eprintln!("lib::get_home: Couldn't get $HOME on Linux: {why:?}");
|
||||
process::exit(1);
|
||||
}
|
||||
},
|
||||
"windows" => match std::env::var("userprofile") {
|
||||
Ok(var) => var,
|
||||
Err(why) => {
|
||||
eprintln!("lib::get_home: Couldn't get $userprofile on Windows: {why:?}");
|
||||
process::exit(1)
|
||||
}
|
||||
},
|
||||
_ => match std::env::var("HOME") {
|
||||
Ok(var) => var,
|
||||
Err(why) => {
|
||||
eprintln!("lib::get_home: Couldn't get $HOME on other OS: {why:?}");
|
||||
process::exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue