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 output;
12pub mod validate;
13pub mod generate;
14
15use clap::{Parser, Subcommand};
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    Generate(generate::Generate),
35}
36
37pub async fn dispatch(meta: Meta) -> anyhow::Result<()> {
38    match meta {
39        Meta::Build(build) => build::build(build),
40        Meta::Solc(solc) => solc::dispatch(solc),
41        Meta::Magic(magic) => magic::dispatch(magic),
42        Meta::Schema(schema) => schema::dispatch(schema),
43        Meta::Validate(validate) => validate::validate(validate),
44        Meta::Generate(generate) => generate::generate(generate),
45    }
46}
47
48pub async fn main() -> anyhow::Result<()> {
49    tracing::subscriber::set_global_default(tracing_subscriber::fmt::Subscriber::new())?;
50    let cli = Cli::parse();
51    dispatch(cli.meta).await
52}