Skip to main content

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 schema_check;
12pub mod output;
13pub mod subgraph;
14pub mod validate;
15pub mod generate;
16
17use clap::{Parser, Subcommand};
18
19#[derive(Parser)]
20#[command(author, version, about, long_about = None)]
21struct Cli {
22    #[command(subcommand)]
23    meta: Meta,
24}
25
26#[derive(Subcommand)]
27pub enum Meta {
28    #[command(subcommand)]
29    Schema(schema::Schema),
30    Validate(validate::Validate),
31    SchemaCheck(schema_check::SchemaCheck),
32    #[command(subcommand)]
33    Magic(magic::Magic),
34    Build(build::Build),
35    #[command(subcommand)]
36    Solc(solc::Solc),
37    #[command(subcommand)]
38    Subgraph(subgraph::Sg),
39    Generate(generate::Generate),
40}
41
42pub async fn dispatch(meta: Meta) -> anyhow::Result<()> {
43    match meta {
44        Meta::Build(build) => build::build(build),
45        Meta::Solc(solc) => solc::dispatch(solc),
46        Meta::Subgraph(sg) => subgraph::dispatch(sg),
47        Meta::Magic(magic) => magic::dispatch(magic),
48        Meta::Schema(schema) => schema::dispatch(schema),
49        Meta::Validate(validate) => validate::validate(validate),
50        Meta::SchemaCheck(c) => schema_check::schema_check(c).await,
51        Meta::Generate(generate) => generate::generate(generate),
52    }
53}
54
55pub async fn main() -> anyhow::Result<()> {
56    tracing::subscriber::set_global_default(tracing_subscriber::fmt::Subscriber::new())?;
57    let cli = Cli::parse();
58    dispatch(cli.meta).await
59}