mod app;
mod forward;
mod input;
mod stream;
mod tracer;
mod ui;
mod watch;
use clap::Parser;
use prt_core::core::scanner;
use prt_core::i18n;
use prt_core::model::ExportFormat;
#[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ValueEnum)]
enum CliExportFormat {
Json,
Csv,
}
impl From<CliExportFormat> for ExportFormat {
fn from(f: CliExportFormat) -> Self {
match f {
CliExportFormat::Json => ExportFormat::Json,
CliExportFormat::Csv => ExportFormat::Csv,
}
}
}
#[derive(Parser)]
#[command(name = "prt", about = "Network port monitor")]
struct Cli {
#[arg(long, value_enum)]
export: Option<CliExportFormat>,
#[arg(long)]
json: bool,
#[arg(long)]
lang: Option<String>,
#[command(subcommand)]
command: Option<Commands>,
}
#[derive(clap::Subcommand)]
enum Commands {
Watch {
#[arg(required = true)]
ports: Vec<u16>,
},
}
fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
let lang = match &cli.lang {
Some(l) => i18n::parse_lang(l),
None => i18n::detect_locale(),
};
i18n::set_lang(lang);
if let Some(format) = cli.export {
let entries = scanner::scan()?;
let output = scanner::export(&entries, format.into())?;
print!("{output}");
return Ok(());
}
if cli.json {
return stream::run_json_stream();
}
if let Some(Commands::Watch { ports }) = cli.command {
return watch::run_watch(ports);
}
app::run()
}