feat(cli): override static files datadir (#7212)

Co-authored-by: Oliver Nordbjerg <onbjerg@users.noreply.github.com>
Co-authored-by: Alexey Shekhirin <a.shekhirin@gmail.com>
Co-authored-by: Oliver Nordbjerg <hi@notbjerg.me>
This commit is contained in:
back
2024-06-03 09:47:15 -07:00
committed by GitHub
parent 994f98f12d
commit 4522fd8baf
50 changed files with 460 additions and 646 deletions

View File

@@ -0,0 +1,53 @@
//! clap [Args](clap::Args) for datadir config
use crate::dirs::{ChainPath, DataDirPath, MaybePlatformPath};
use clap::Args;
use reth_primitives::Chain;
use std::path::PathBuf;
/// Parameters for datadir configuration
#[derive(Debug, Args, PartialEq, Eq, Default, Clone)]
#[command(next_help_heading = "Datadir")]
pub struct DatadirArgs {
/// The path to the data dir for all reth files and subdirectories.
///
/// Defaults to the OS-specific data directory:
///
/// - Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
/// - Windows: `{FOLDERID_RoamingAppData}/reth/`
/// - macOS: `$HOME/Library/Application Support/reth/`
#[arg(long, value_name = "DATA_DIR", verbatim_doc_comment, default_value_t)]
pub datadir: MaybePlatformPath<DataDirPath>,
/// The absolute path to store static files in.
#[arg(long = "datadir.static_files", verbatim_doc_comment, value_name = "PATH")]
pub static_files_path: Option<PathBuf>,
}
impl DatadirArgs {
/// Resolves the final datadir path.
pub fn resolve_datadir(self, chain: Chain) -> ChainPath<DataDirPath> {
let datadir = self.datadir.clone();
datadir.unwrap_or_chain_default(chain, self)
}
}
#[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_datadir_args() {
let default_args = DatadirArgs::default();
let args = CommandParser::<DatadirArgs>::parse_from(["reth"]).args;
assert_eq!(args, default_args);
}
}

View File

@@ -51,6 +51,10 @@ pub use dev::DevArgs;
mod pruning;
pub use pruning::PruningArgs;
/// DatadirArgs for configuring data storage paths
mod datadir_args;
pub use datadir_args::DatadirArgs;
pub mod utils;
pub mod types;