subgraph/cli_args/
mod.rs

1use serde::Serialize;
2use std::path::PathBuf;
3
4use clap::{builder::PossibleValuesParser, Parser, ValueHint};
5
6mod generate_keypair;
7
8/// Command line arguments for the Subgraph Service.
9#[derive(Parser, Debug, Serialize, Clone)]
10#[command(author, version, about, long_about = None)]
11pub struct CliArgs {
12    /// Path to the subgraph config file.
13    #[arg(short, long, value_hint = ValueHint::DirPath)]
14    pub config: Option<PathBuf>,
15
16    /// Service log level.
17    #[serde(rename = "log-level")]
18    #[arg(short, long, value_parser = PossibleValuesParser::new(["info", "debug", "info", "warn", "error", "trace"]))]
19    pub log_level: Option<String>,
20
21    /// The port this service runs on.
22    #[arg(short, long)]
23    pub port: Option<u16>,
24
25    /// Allow service to run on 0.0.0.0, all interfaces.
26    #[arg(long)]
27    pub host: bool,
28
29    /// Run migrations
30    #[arg(short, long, value_parser = PossibleValuesParser::new(["run", "revert"]))]
31    pub migrate: Option<String>,
32
33    ///Generate Key Pair
34    #[arg(short, long)]
35    pub generate_keypair: bool,
36
37    /// Start the service in watch mode. Changes made to the subgraph config file will be
38    /// automatically applied. The service will restart.
39    #[arg(short, long)]
40    pub watch: bool,
41}
42
43impl CliArgs {
44    /// Execute functions based on the flags passed to the service.
45    pub fn handle_flags(&self) -> Result<(), Box<dyn std::error::Error>> {
46        self.generate_keypair()?;
47        Ok(())
48    }
49}