mod cli; mod errors; use std::path::{Path, PathBuf}; use errors::*; mod viewer; pub fn main() -> Result<()> { error_stack::Report::set_color_mode(error_stack::fmt::ColorMode::Color); error_stack::Report::set_charset(error_stack::fmt::Charset::Utf8); let args = ::parse(); if let Some(shell) = args.completions { cli::Cli::completions(shell); return Ok(()); } let input = args .input .canonicalize() .change_context(Error) .attach("Failed to canonicalize path")?; let files = walker(&input); // if files.is_empty() { // return Err(Error) // .attach("No files found in the folder") // .attach(input.display().to_string()); // } viewer::run(files); Ok(()) } // Returns all the children (if a dir) and sister (if an image) files of the input path fn walker(input: impl AsRef) -> Vec { let mut tb = ignore::types::TypesBuilder::new(); gpui::Img::extensions().iter().for_each(|ext| { tb.add("image", &format!("*.{ext}")) .expect("Failed to add image type"); }); ignore::WalkBuilder::new(input) .types( tb.select("image") .add_defaults() .build() .expect("Failed to build type finder"), ) .git_ignore(false) .sort_by_file_name(|a, b| a.cmp(b)) .build() .filter_map(|e| e.ok()) .filter(|e| e.file_type().map_or(false, |ft| ft.is_file())) .map(|e| e.path().to_path_buf()) .collect() }