use std::process::ExitCode;
use twinleaf_tools::{Commands, DumpSubcommands, LogSubcommands, RPCSubcommands, TioCli};
use clap::Parser;
use twinleaf_tools::tools::{
tio_proxy::run_proxy,
tio_text_proxy::run_text_proxy,
tio_monitor::run_monitor,
tio_health::run_health,
tio_tool::{
list_rpcs,
rpc,
rpc_dump,
dump,
data_dump_all_deprecated,
data_dump_deprecated,
meta_dump_deprecated,
log,
log_dump,
log_data_dump_deprecated,
log_metadata,
meta_reroute,
log_csv,
log_hdf,
firmware_upgrade,
}
};
fn main() -> ExitCode {
let cli = TioCli::parse();
let result = match cli.command {
Commands::Proxy(proxy_cli) => run_proxy(proxy_cli),
Commands::Monitor{
tio,
all,
fps,
colors
} => run_monitor(tio, all, fps, colors),
Commands::Health(health_cli) => run_health(health_cli),
Commands::NmeaProxy{tio, tcp_port} => run_text_proxy(tio, tcp_port),
Commands::Rpc {
tio,
subcommands,
rpc_name,
rpc_arg,
req_type,
rep_type,
debug
} => {
let _= match subcommands{
Some(RPCSubcommands::List { tio }) => list_rpcs(&tio),
Some(RPCSubcommands::Dump { tio, rpc_name, capture })
=> rpc_dump(&tio, rpc_name, capture),
None => rpc(&tio, rpc_name.unwrap_or("".to_string()), rpc_arg, req_type, rep_type, debug),
};
Ok(())
}
Commands::Dump {
tio,
subcommands,
data,
meta,
depth,
} => {
let _ = match subcommands {
Some(DumpSubcommands::Data { tio }) => data_dump_deprecated(&tio),
Some(DumpSubcommands::DataAll { tio }) => data_dump_all_deprecated(&tio),
Some(DumpSubcommands::Meta { tio }) => meta_dump_deprecated(&tio),
None => dump(&tio, data, meta, depth),
};
Ok(())
}
Commands::Log {
tio,
subcommands,
file,
unbuffered,
raw,
depth,
} => {
let _= match subcommands{
Some(LogSubcommands::Metadata { tio, file })
=> log_metadata(&tio, file),
Some(LogSubcommands::Dump { files, data, meta, sensor, depth })
=> log_dump(files, data, meta, sensor, depth),
Some(LogSubcommands::DataDump { files}) => log_data_dump_deprecated(files),
Some(LogSubcommands::Csv { args, sensor, output})
=> log_csv( args, sensor, output),
Some(LogSubcommands::Hdf { files, output, filter, compress, debug, split_level, split_policy })
=> log_hdf(files, output, filter, compress, debug, split_level, split_policy),
None => log(&tio, file, unbuffered, raw, depth),
};
Ok(())
}
Commands::MetaReroute { input, route, output }
=> meta_reroute(input, route, output),
Commands::FirmwareUpgrade { tio, firmware_path } => firmware_upgrade(&tio, firmware_path),
};
if result.is_ok() {
ExitCode::SUCCESS
} else {
eprintln!("FAILED");
ExitCode::FAILURE
}
}