mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-31 10:08:13 -05:00
48 lines
1.4 KiB
Rust
48 lines
1.4 KiB
Rust
//! clap [Args](clap::Args) for database configuration
|
|
|
|
use crate::version::default_client_version;
|
|
use clap::Args;
|
|
use reth_storage_errors::db::LogLevel;
|
|
|
|
/// Parameters for database configuration
|
|
#[derive(Debug, Args, PartialEq, Eq, Default, Clone, Copy)]
|
|
#[command(next_help_heading = "Database")]
|
|
pub struct DatabaseArgs {
|
|
/// Database logging level. Levels higher than "notice" require a debug build.
|
|
#[arg(long = "db.log-level", value_enum)]
|
|
pub log_level: Option<LogLevel>,
|
|
/// Open environment in exclusive/monopolistic mode. Makes it possible to open a database on an
|
|
/// NFS volume.
|
|
#[arg(long = "db.exclusive")]
|
|
pub exclusive: Option<bool>,
|
|
}
|
|
|
|
impl DatabaseArgs {
|
|
/// Returns default database arguments with configured log level and client version.
|
|
pub fn database_args(&self) -> reth_db::mdbx::DatabaseArguments {
|
|
reth_db::mdbx::DatabaseArguments::new(default_client_version())
|
|
.with_log_level(self.log_level)
|
|
.with_exclusive(self.exclusive)
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use clap::Parser;
|
|
|
|
/// A helper type to parse Args more easily
|
|
#[derive(Parser)]
|
|
struct CommandParser<T: Args> {
|
|
#[command(flatten)]
|
|
args: T,
|
|
}
|
|
|
|
#[test]
|
|
fn test_parse_database_args() {
|
|
let default_args = DatabaseArgs::default();
|
|
let args = CommandParser::<DatabaseArgs>::parse_from(["reth"]).args;
|
|
assert_eq!(args, default_args);
|
|
}
|
|
}
|