Skip to main content

webgraph_cli/build/
mod.rs

1/*
2 * SPDX-FileCopyrightText: 2023 Tommaso Fontana
3 * SPDX-FileCopyrightText: 2026 Sebastiano Vigna
4 *
5 * SPDX-License-Identifier: Apache-2.0 OR MIT
6 */
7
8use anyhow::Result;
9use clap::{Command, Parser, Subcommand};
10use clap_complete::shells::Shell;
11
12pub mod dcf;
13pub mod ef;
14pub mod offsets;
15
16/// Builds accessory graph data structures (e.g., offsets, ef, dcf).​
17#[derive(Subcommand, Debug)]
18#[command(name = "build")]
19pub enum SubCommands {
20    Ef(ef::CliArgs),
21    Dcf(dcf::CliArgs),
22    Offsets(offsets::CliArgs),
23    Complete(CompleteArgs),
24}
25
26/// Generates shell completions. Use with `source <(webgraph build complete
27/// $SHELL)` to install completions locally, or redirect standard output to a
28/// proper location for a permanent installation.​
29#[derive(Parser, Debug)]
30#[command(next_line_help = true)]
31pub struct CompleteArgs {
32    shell: Shell,
33}
34
35pub fn main(subcommand: SubCommands, mut top_command: Command) -> Result<()> {
36    match subcommand {
37        SubCommands::Ef(args) => ef::main(args),
38        SubCommands::Dcf(args) => dcf::main(args),
39        SubCommands::Offsets(args) => offsets::main(args),
40        SubCommands::Complete(args) => {
41            clap_complete::generate(
42                args.shell,
43                &mut top_command,
44                "webgraph",
45                &mut std::io::stdout(),
46            );
47            Ok(())
48        }
49    }
50}