reth_cli_commands/
config_cmd.rs

1//! CLI command to show configs.
2
3use clap::Parser;
4use eyre::{bail, WrapErr};
5use reth_config::Config;
6use std::path::PathBuf;
7/// `reth config` command
8#[derive(Debug, Parser)]
9pub struct Command {
10    /// The path to the configuration file to use.
11    #[arg(long, value_name = "FILE", verbatim_doc_comment)]
12    config: Option<PathBuf>,
13
14    /// Show the default config
15    #[arg(long, verbatim_doc_comment, conflicts_with = "config")]
16    default: bool,
17}
18
19impl Command {
20    /// Execute `config` command
21    pub async fn execute(&self) -> eyre::Result<()> {
22        let config = if self.default {
23            Config::default()
24        } else {
25            let path = match self.config.as_ref() {
26                Some(path) => path,
27                None => bail!("No config file provided. Use --config <FILE> or pass --default"),
28            };
29            if !path.exists() {
30                bail!("Config file does not exist: {}", path.display());
31            }
32            Config::from_path(path)
33                .wrap_err_with(|| format!("Could not load config file: {}", path.display()))?
34        };
35        println!("{}", toml::to_string_pretty(&config)?);
36        Ok(())
37    }
38}