1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//! CLI command to show configs.

use std::path::PathBuf;

use clap::Parser;
use eyre::{bail, WrapErr};
use reth_config::Config;

/// `reth config` command
#[derive(Debug, Parser)]
pub struct Command {
    /// The path to the configuration file to use.
    #[arg(long, value_name = "FILE", verbatim_doc_comment)]
    config: Option<PathBuf>,

    /// Show the default config
    #[arg(long, verbatim_doc_comment, conflicts_with = "config")]
    default: bool,
}

impl Command {
    /// Execute `config` command
    pub async fn execute(&self) -> eyre::Result<()> {
        let config = if self.default {
            Config::default()
        } else {
            let path = self.config.clone().unwrap_or_default();
            // Check if the file exists
            if !path.exists() {
                bail!("Config file does not exist: {}", path.display());
            }
            // Read the configuration file
            Config::from_path(&path)
                .wrap_err_with(|| format!("Could not load config file: {}", path.display()))?
        };
        println!("{}", toml::to_string_pretty(&config)?);
        Ok(())
    }
}