rain_metadata/cli/
mod.rs

1//! Represents a [mod@clap] based CLI app module
2//!
3//! struct, enums that use `clap` derive macro to produce CLI commands, argument
4//! and options with underlying functions to handle each scenario.
5//! enabled by default or by `cli` feature if default features i off.
6
7pub mod solc;
8pub mod build;
9pub mod magic;
10pub mod schema;
11pub mod output;
12pub mod subgraph;
13pub mod validate;
14
15use clap::{Parser, Subcommand, command};
16
17#[derive(Parser)]
18#[command(author, version, about, long_about = None)]
19struct Cli {
20    #[command(subcommand)]
21    meta: Meta,
22}
23
24#[derive(Subcommand)]
25pub enum Meta {
26    #[command(subcommand)]
27    Schema(schema::Schema),
28    Validate(validate::Validate),
29    #[command(subcommand)]
30    Magic(magic::Magic),
31    Build(build::Build),
32    #[command(subcommand)]
33    Solc(solc::Solc),
34    #[command(subcommand)]
35    Subgraph(subgraph::Sg),
36}
37
38pub fn dispatch(meta: Meta) -> anyhow::Result<()> {
39    match meta {
40        Meta::Build(build) => build::build(build),
41        Meta::Solc(solc) => solc::dispatch(solc),
42        Meta::Subgraph(sg) => subgraph::dispatch(sg),
43        Meta::Magic(magic) => magic::dispatch(magic),
44        Meta::Schema(schema) => schema::dispatch(schema),
45        Meta::Validate(validate) => validate::validate(validate),
46    }
47}
48
49pub fn main() -> anyhow::Result<()> {
50    tracing::subscriber::set_global_default(tracing_subscriber::fmt::Subscriber::new())?;
51    let cli = Cli::parse();
52    dispatch(cli.meta)
53}