pub mod cli;
pub mod error;
pub mod config;
pub mod display;
pub mod fs;
pub mod git;
pub mod descriptions;
pub use cli::Cli;
pub use error::{LsPlusError, Result};
use clap::Parser;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
let result = run(cli).await;
match result {
Ok(_) => Ok(()), Err(e) => {
eprintln!("Error: {e}");
std::process::exit(1);
}
}
}
async fn run(cli: Cli) -> Result<()> {
if let Some(command) = cli.command {
return handle_command(command).await;
}
let entries = fs::list_directory(&cli.path, &cli).await?;
display::render_entries(&entries, &cli).await?;
Ok(())
}
async fn handle_command(command: cli::Commands) -> Result<()> {
match command {
cli::Commands::Config { action } => config::handle_config_command(action).await,
cli::Commands::Tree {
path,
max_depth,
all,
} => {
let tree_cli = create_tree_cli(path, max_depth, all);
let entries =
fs::list_directory_recursive(&tree_cli.path, &tree_cli, max_depth).await?;
display::render_tree(&entries, max_depth).await
}
cli::Commands::Find {
pattern,
path,
ignore_case,
file_type,
} => {
let find_cli = create_find_cli(path, pattern, ignore_case, file_type);
let matches = fs::find_files(&find_cli).await?;
display::render_search_results(&matches, &find_cli).await
}
cli::Commands::Describe { action } => descriptions::handle_describe_command(action).await,
}
}
fn create_tree_cli(path: std::path::PathBuf, _max_depth: Option<usize>, all: bool) -> Cli {
Cli {
path, all, format: cli::FormatOption::Tree, ..Default::default() }
}
fn create_find_cli(
path: std::path::PathBuf,
_pattern: String,
_ignore_case: bool,
_file_type: Option<cli::FileTypeFilter>,
) -> Cli {
Cli {
path, ..Default::default() }
}
impl Default for Cli {
fn default() -> Self {
Self {
path: ".".into(), all: false, long: false, human_readable: false, time: false, reverse: false, directories_first: false, follow_links: false, icons: false, color: cli::ColorOption::Auto, format: cli::FormatOption::Default, file_type: None, max_depth: None, git: false, command: None, }
}
}