reth_node_core/args/
datadir_args.rs

1//! clap [Args](clap::Args) for datadir config
2
3use crate::dirs::{ChainPath, DataDirPath, MaybePlatformPath};
4use clap::Args;
5use reth_chainspec::Chain;
6use std::path::PathBuf;
7
8/// Parameters for datadir configuration
9#[derive(Debug, Args, PartialEq, Eq, Default, Clone)]
10#[command(next_help_heading = "Datadir")]
11pub struct DatadirArgs {
12    /// The path to the data dir for all reth files and subdirectories.
13    ///
14    /// Defaults to the OS-specific data directory:
15    ///
16    /// - Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
17    /// - Windows: `{FOLDERID_RoamingAppData}/reth/`
18    /// - macOS: `$HOME/Library/Application Support/reth/`
19    #[arg(long, value_name = "DATA_DIR", verbatim_doc_comment, default_value_t)]
20    pub datadir: MaybePlatformPath<DataDirPath>,
21
22    /// The absolute path to store static files in.
23    #[arg(
24        long = "datadir.static-files",
25        alias = "datadir.static_files",
26        value_name = "PATH",
27        verbatim_doc_comment
28    )]
29    pub static_files_path: Option<PathBuf>,
30}
31
32impl DatadirArgs {
33    /// Resolves the final datadir path.
34    pub fn resolve_datadir(self, chain: Chain) -> ChainPath<DataDirPath> {
35        let datadir = self.datadir.clone();
36        datadir.unwrap_or_chain_default(chain, self)
37    }
38}
39
40#[cfg(test)]
41mod tests {
42    use super::*;
43    use clap::Parser;
44
45    /// A helper type to parse Args more easily
46    #[derive(Parser)]
47    struct CommandParser<T: Args> {
48        #[command(flatten)]
49        args: T,
50    }
51
52    #[test]
53    fn test_parse_datadir_args() {
54        let default_args = DatadirArgs::default();
55        let args = CommandParser::<DatadirArgs>::parse_from(["reth"]).args;
56        assert_eq!(args, default_args);
57    }
58}