mod cli;
mod command;
mod filter;
use anyhow::Result;
use clap::CommandFactory;
use clap::Parser;
use cli::Action;
use cli::Cli;
use iceoryx2_cli::install_panic_handlers;
use iceoryx2_log::error;
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 let Some(action) = cli.action {
match action {
Action::Notify(options) => {
if let Err(e) = command::notify(options, cli.format) {
error!("failed to notify service: {}", e);
}
}
Action::Listen(options) => {
if let Err(e) = command::listen(options, cli.format) {
error!("failed to wait for notifications: {}", e);
}
}
Action::List(options) => {
if let Err(e) = command::list(options.filter, cli.format) {
error!("failed to list services: {}", e);
}
}
Action::Details(options) => {
if let Err(e) = command::details(options.service, options.filter, cli.format) {
error!("failed to retrieve service details: {}", e);
}
}
Action::Publish(options) => {
if let Err(e) = command::publish(options, cli.format) {
error!("failed to publish messages: {}", e);
}
}
Action::Subscribe(options) => {
if let Err(e) = command::subscribe(options, cli.format) {
error!("failed to subscribe and receive messages: {}", e);
}
}
Action::Record(options) => {
if let Err(e) = command::record(options, cli.format) {
error!("failed to record data: {}", e);
}
}
Action::Replay(options) => {
if let Err(e) = command::replay(options, cli.format) {
error!("failed to replay data: {}", e);
}
}
Action::Hz(options) => {
if let Err(e) = command::hz(options, cli.format) {
error!("failed to measure service frequency: {}", e);
}
}
Action::Discovery(options) => {
let should_publish = !options.disable_publish;
let should_notify = !options.disable_notify;
if let Err(e) = command::discovery(
options.rate,
options.detailed,
should_publish,
options.max_subscribers,
should_notify,
options.max_listeners,
cli.format,
) {
error!("failed to run service discovery: {:#}", e)
}
}
}
} else {
Cli::command().print_help().expect("Failed to print help");
}
Ok(())
}