cometindex/opt.rs
1use std::{path::PathBuf, time::Duration};
2
3use anyhow::{Error, Result};
4use clap::Parser;
5
6/// This struct represents the command-line options
7#[derive(Clone, Debug, Parser)]
8#[clap(
9 name = "cometindex",
10 about = "processes raw events emitted by cometbft applications",
11 version
12)]
13pub struct Options {
14 /// PostgreSQL database connection string for the source database with raw events
15 #[clap(short, long)]
16 pub src_database_url: String,
17
18 /// PostgreSQL database connection string for the destination database with compiled data
19 #[clap(short, long)]
20 pub dst_database_url: String,
21
22 /// Filter for only events with this chain ID.
23 #[clap(short, long)]
24 pub chain_id: Option<String>,
25
26 /// The rate at which to poll for changes, in milliseconds.
27 #[clap(short, long, default_value = "500", value_parser = parse_poll_ms)]
28 pub poll_ms: Duration,
29
30 /// A file path for the genesis file to use when initializing the indexer.
31 #[clap(short, long)]
32 pub genesis_json: PathBuf,
33
34 /// By default, the program will run as a daemon, continuously polling the src database
35 /// for new events. If --exit-on-catchup is set, the program will instead exit after
36 /// it has indexed all events in the src database. Useful for batch jobs.
37 #[clap(long)]
38 pub exit_on_catchup: bool,
39}
40
41/// Parses a string containing a [`Duration`], represented as a number of milliseconds.
42fn parse_poll_ms(s: &str) -> Result<Duration> {
43 s.parse().map(Duration::from_millis).map_err(Error::from)
44}