fn main()

in src/main.rs [140:246]


fn main() {
    let matches = cli().get_matches();

    let verbosity = match matches.get_one::<String>("verbose").unwrap().as_str() {
        "off" => LevelFilter::Off,
        "warn" => LevelFilter::Warn,
        "info" => LevelFilter::Info,
        "debug" => LevelFilter::Debug,
        "trace" => LevelFilter::Trace,
        _ => LevelFilter::Error,
    };

    // Init the logger
    let mut config = ConfigBuilder::new();
    // Note that this will fail if we have more than 1 thread running, but this
    // should be fine here at startup
    let _res = config.set_time_offset_to_local();
    let _ = TermLogger::init(
        verbosity,
        config.build(),
        TerminalMode::Stderr,
        ColorChoice::Auto,
    );

    // Set a panic hook to redirect to the logger
    panic::set_hook(Box::new(|panic_info| {
        let (filename, line) = panic_info
            .location()
            .map(|loc| (loc.file(), loc.line()))
            .unwrap_or(("<unknown>", 0));
        let cause = panic_info
            .payload()
            .downcast_ref::<String>()
            .map(String::deref)
            .unwrap_or_else(|| {
                panic_info
                    .payload()
                    .downcast_ref::<&str>()
                    .copied()
                    .unwrap_or("<cause unknown>")
            });
        error!("A panic occurred at {}:{}: {}", filename, line, cause);
    }));

    let output = matches.get_one::<String>("output").map(String::as_str);
    let filenames = to_vec(matches.get_many::<String>("filenames").unwrap());
    let symbol_server = matches
        .get_one::<String>("symbol_server")
        .map(String::as_str);
    let store = matches.get_one::<String>("store").map(String::as_str);
    let debug_id = matches.get_one::<String>("debug_id").map(String::as_str);
    let code_id = matches.get_one::<String>("code_id").map(String::as_str);
    let arch = matches.get_one::<String>("arch").unwrap().as_str();
    let check_cfi = matches.get_flag("check_cfi");
    let emit_inlines = matches.get_flag("inlines");
    let mapping_var = matches.get_many("mapping_var").map(to_vec);
    let mapping_src = matches.get_many("mapping_src").map(to_vec);
    let mapping_dest = matches.get_many("mapping_dest").map(to_vec);
    let mapping_file = matches
        .get_one::<String>("mapping_file")
        .map(String::as_str);
    get_extra_info(&matches);

    let num_jobs = if let Ok(num_jobs) = matches
        .get_one::<String>("num_jobs")
        .unwrap()
        .parse::<usize>()
    {
        num_jobs
    } else {
        num_cpus::get()
    };

    let action = if matches.get_flag("list_arch") {
        Action::ListArch
    } else {
        let output = match (output, store) {
            (Some(out), Some(store)) => dumper::Output::FileAndStore {
                file: out.into(),
                store_directory: store.into(),
            },
            (Some(out), None) => dumper::Output::File(out.into()),
            (None, Some(store)) => dumper::Output::Store(store.into()),
            (None, None) => dumper::Output::File(dumper::FileOutput::Stdout),
        };

        Action::Dump(dumper::Config {
            output,
            symbol_server,
            debug_id,
            code_id,
            arch,
            num_jobs,
            check_cfi,
            emit_inlines,
            mapping_var,
            mapping_src,
            mapping_dest,
            mapping_file,
        })
    };

    if let Err(e) = action.action(&filenames) {
        eprintln!("{e}");
        std::process::exit(1);
    }
}