rsfindlibs 0.1.1

Find shared libraries in the system and provide a useful macro to load them.
Documentation
use rsfindlibs::find;
use log::LevelFilter;
use env_logger::Builder;
use std::io::Write;

use clap::{Parser};

#[derive(Parser)]
#[command(version, about, long_about = None)]
struct Cli {
    /// The name of the library to find, e.g. "fdb5"
    name: String,

    /// Optional package name (if different from the library name)
    pkg_name: Option<String>,

    /// Turn debugging information on
    #[arg(short, long, action = clap::ArgAction::Count)]
    verbose: u8,
}

fn main() {
    let cli = Cli::parse();

    // Set up logging
    Builder::new()
        .format(|buf, record| {
            writeln!(buf, "{}", record.args()) // Only log the message itself
        })
        .filter(None, if cli.verbose > 0 { LevelFilter::Debug } else { LevelFilter::Info })
        .parse_env("RSFINDLIBS_DEBUG")
        .init();

    // Get arguments
    let lib_name = cli.name.as_str();
    let pkg_name = cli.pkg_name.as_deref();

    // Perform the library search
    match find(lib_name, pkg_name) {
        Some(path) => {
            println!("Library found: {}", path);
        }
        None => {
            eprintln!("Library not found");
            std::process::exit(1);
        }
    }
}