mod cli;
mod command;
use clap::Parser;
use cli::Cli;
use iceoryx2_cli::install_panic_handlers;
use iceoryx2_log::LogLevel;
use iceoryx2_log::set_log_level_from_env_or;
fn main() -> anyhow::Result<()> {
install_panic_handlers!();
set_log_level_from_env_or(LogLevel::Info);
let cli = Cli::parse();
if cli.list {
if let Err(e) = command::list() {
eprintln!("Failed to list commands: {e}");
}
} else if cli.paths {
if let Err(e) = command::paths() {
eprintln!("Failed to list search paths: {e}");
}
} else if !cli.external_command.is_empty() {
let command_name = &cli.external_command[0];
let command_args = if cli.external_command.len() > 1 {
Some(&cli.external_command[1..])
} else {
None
};
if let Err(e) = command::execute(command_name, command_args) {
eprintln!("Failed to execute command: {e}");
}
} else {
if let Err(e) = command::list() {
eprintln!("Failed to list commands: {e}");
}
}
Ok(())
}