feat(main): improve input handling and error reporting
Some checks failed
build / checks-matrix (push) Successful in 19m29s
build / codecov (push) Failing after 19m22s
docs / docs (push) Failing after 28m47s
build / checks-build (push) Has been cancelled

This commit is contained in:
uttarayan21
2025-10-08 03:06:29 +05:30
parent 63e05c994b
commit dcefe0f23d

View File

@@ -5,14 +5,23 @@ use std::path::{Path, PathBuf};
use errors::*; use errors::*;
mod viewer; mod viewer;
pub fn main() -> Result<()> { 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 = <cli::Cli as clap::Parser>::parse(); let args = <cli::Cli as clap::Parser>::parse();
if let Some(shell) = args.completions { if let Some(shell) = args.completions {
cli::Cli::completions(shell); cli::Cli::completions(shell);
return Ok(()); return Ok(());
} }
let files = walker(args.input); let input = args
.input
.canonicalize()
.change_context(Error)
.attach("Failed to canonicalize path")?;
let files = walker(&input);
if files.is_empty() { if files.is_empty() {
return Err(Error).attach("No files found"); return Err(Error)
.attach("No files found in the folder")
.attach(input.display().to_string());
} }
viewer::run(files); viewer::run(files);
@@ -33,6 +42,7 @@ fn walker(input: impl AsRef<Path>) -> Vec<PathBuf> {
.build() .build()
.expect("Failed to build type finder"), .expect("Failed to build type finder"),
) )
.git_ignore(false)
.sort_by_file_name(|a, b| a.cmp(b)) .sort_by_file_name(|a, b| a.cmp(b))
.build() .build()
.filter_map(|e| e.ok()) .filter_map(|e| e.ok())