Skip to main content

swh_graph/
cli.rs

1/*
2 * Copyright (C) 2023-2026  The Software Heritage developers
3 * See the AUTHORS file at the top-level directory of this distribution
4 * License: GNU General Public License version 3, or any later version
5 * See top-level LICENSE file for more information
6 */
7
8//! Utilities to build a Command-Line Interface
9
10use std::path::Path;
11
12use anyhow::{Context, Result};
13use clap::ValueEnum;
14
15#[derive(Copy, Clone, Debug, ValueEnum)]
16pub enum MphAlgorithm {
17    Fmphgo,
18    Pthash,
19    Cmph,
20}
21
22pub fn load_mph(mph_algo: MphAlgorithm, path: &Path) -> Result<crate::mph::DynMphf> {
23    Ok(match mph_algo {
24        MphAlgorithm::Cmph => crate::java_compat::mph::gov::GOVMPH::load(path)
25            .context("Cannot load mph")?
26            .into(),
27        MphAlgorithm::Fmphgo => crate::mph::SwhidFmphgo::load(path)
28            .context("Cannot load mph")?
29            .into(),
30        MphAlgorithm::Pthash => {
31            #[cfg(not(feature = "pthash"))]
32            anyhow::bail!("pthash support is disabled. Recompile with --features pthash");
33            #[cfg(feature = "pthash")]
34            crate::mph::SwhidPthash::load(path)
35                .context("Cannot load mph")?
36                .into()
37        }
38    })
39}