rain_metadata/cli/subgraph/
mod.rs

1use clap::{Subcommand, Parser};
2use crate::subgraph::KnownSubgraphs;
3
4/// command related to subgraphs
5#[derive(Subcommand, strum::Display)]
6pub enum Sg {
7    /// show all subgraph URLs
8    All,
9    /// show all native parser subgraph endpoint URLs
10    NativeParser,
11    /// show all legacy subgraph endpoint URLs
12    Legacy,
13    /// show subgraph endpoint URLs of specific chain
14    Chain(Chain),
15}
16
17#[derive(Parser)]
18pub struct Chain {
19    /// the chain id of the network
20    id: u64,
21}
22
23pub fn dispatch(sg: Sg) -> anyhow::Result<()> {
24    match sg {
25        Sg::All => {
26            for url in KnownSubgraphs::ALL.iter() {
27                println!("{url}")
28            }
29        }
30        Sg::NativeParser => {
31            for url in KnownSubgraphs::NP.iter() {
32                println!("{url}")
33            }
34        }
35        Sg::Legacy => {
36            for url in KnownSubgraphs::LEGACY.iter() {
37                println!("{url}")
38            }
39        }
40        Sg::Chain(chain_id) => {
41            for url in KnownSubgraphs::of_chain(chain_id.id)?.iter() {
42                println!("{url}")
43            }
44        }
45    };
46    Ok(())
47}