Skip to main content

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 => {
28                    bail!("No config file provided. Use --config <FILE> or pass --default");
29                }
30            };
31            if !path.exists() {
32                bail!("Config file does not exist: {}", path.display());
33            }
34            Config::from_path(path)
35                .wrap_err_with(|| format!("Could not load config file: {}", path.display()))?
36        };
37        println!("{}", toml::to_string_pretty(&config)?);
38        Ok(())
39    }
40}