Skip to main content

webgraph_cli/rank/
mod.rs

1/*
2 * SPDX-FileCopyrightText: 2026 Sebastiano Vigna
3 *
4 * SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
5 */
6use crate::{build_info, pretty_print_elapsed};
7use anyhow::Result;
8use clap::{Parser, Subcommand};
9
10use super::GlobalArgs;
11
12pub mod pagerank;
13
14#[derive(Subcommand, Debug)]
15#[command(name = "rank")]
16pub enum SubCommands {
17    #[clap(name = "pagerank", visible_alias = "pr")]
18    PageRank(pagerank::CliArgs),
19}
20
21#[derive(Parser, Debug)]
22#[command(name = "webgraph-rank", version=build_info::version_string())]
23/// WebGraph tools computing centrality measures.
24#[doc = include_str!("../common_ps.txt")]
25#[doc = include_str!("../common_env.txt")]
26pub struct Cli {
27    #[clap(flatten)]
28    args: GlobalArgs,
29    #[command(subcommand)]
30    command: SubCommands,
31}
32
33pub fn cli_main<I, T>(args: I) -> Result<()>
34where
35    I: IntoIterator<Item = T>,
36    T: Into<std::ffi::OsString> + Clone,
37{
38    let start = std::time::Instant::now();
39    let cli = Cli::parse_from(args);
40    match cli.command {
41        SubCommands::PageRank(args) => {
42            pagerank::main(cli.args, args)?;
43        }
44    }
45
46    log::info!(
47        "The command took {}",
48        pretty_print_elapsed(start.elapsed().as_secs_f64())
49    );
50
51    Ok(())
52}