use std::{error::Error, path::PathBuf};

use clap::{Parser, Subcommand};
use pcap::Capture;

fn main() -> Result<(), Box<dyn Error>> {
	let Args { file, cmd } = Args::parse();
	let pcap = Capture::from_file(file)?;

	match cmd {
		Cmd::Links => {
			for record in pcap.list_datalinks()? {
				let name = record.get_name().unwrap_or_else(|_| "<unnamed>".into());
				let description = record.get_description().unwrap_or_default();
				println!("link {name} {description}")
			}
		}
	}

	Ok(())
}

#[derive(Parser)]
struct Args {
	file: PathBuf,

	#[command(subcommand)]
	cmd: Cmd,
}

#[derive(Subcommand)]
enum Cmd {
	Links,
}
