mod cli;
mod command;
use anyhow::Result;
use clap::CommandFactory;
use clap::Parser;
use cli::Cli;
use iceoryx2_cli::install_panic_handlers;
use iceoryx2_log::{LogLevel, set_log_level_from_env_or};
fn main() -> Result<()> {
install_panic_handlers!();
set_log_level_from_env_or(LogLevel::Warn);
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 {
Cli::command().print_help().expect("Failed to print help");
}
Ok(())
}