webgraph_cli/dist/
mod.rs

1/*
2 * SPDX-FileCopyrightText: 2025 Tommaso Fontana
3 * SPDX-FileCopyrightText: 2025 Sebastiano Vigna
4 *
5 * SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
6 */
7use crate::{build_info, pretty_print_elapsed};
8use anyhow::Result;
9use clap::{Parser, Subcommand};
10
11use super::GlobalArgs;
12
13pub mod ess;
14pub mod hyperball;
15
16#[derive(Subcommand, Debug)]
17#[command(name = "dist")]
18pub enum SubCommands {
19    #[clap(name = "hyperball", visible_alias = "hb")]
20    HyperBall(hyperball::CliArgs),
21    #[clap(visible_alias = "ess")]
22    ExactSumSweep(ess::CliArgs),
23}
24
25#[derive(Parser, Debug)]
26#[command(name = "webgraph-dist", version=build_info::version_string())]
27/// WebGraph tools computing graph properties based on distances.
28#[doc = include_str!("../common_ps.txt")]
29///
30/// Note that on shells supporting process substitution you compress the results
31/// using a suitable syntax. For example on bash / zsh, you can use the path
32/// `>(zstd > sccs.zstd)`.
33///
34/// Noteworthy environment variables:
35///
36/// - RUST_MIN_STACK: minimum thread stack size (in bytes); we suggest
37///   RUST_MIN_STACK=8388608 (8MiB)
38///
39/// - TMPDIR: where to store temporary files (potentially very large ones)
40///
41/// - RUST_LOG: configuration for env_logger
42///   <https://docs.rs/env_logger/latest/env_logger/>
43pub struct Cli {
44    #[clap(flatten)]
45    args: GlobalArgs,
46    #[command(subcommand)]
47    command: SubCommands,
48}
49
50pub fn cli_main<I, T>(args: I) -> Result<()>
51where
52    I: IntoIterator<Item = T>,
53    T: Into<std::ffi::OsString> + Clone,
54{
55    let start = std::time::Instant::now();
56    let cli = Cli::parse_from(args);
57    match cli.command {
58        SubCommands::HyperBall(args) => {
59            hyperball::main(cli.args, args)?;
60        }
61        SubCommands::ExactSumSweep(args) => {
62            ess::main(cli.args, args)?;
63        }
64    }
65
66    log::info!(
67        "The command took {}",
68        pretty_print_elapsed(start.elapsed().as_secs_f64())
69    );
70
71    Ok(())
72}