Skip to content

Commit

Permalink
feat: add the config command to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
vcastellm committed Nov 21, 2024
1 parent 3a89565 commit 45ab109
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions crates/cdk/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,6 @@ pub(crate) enum Commands {
},
/// Output the corresponding versions of the components
Versions,
/// Output the default config template file
Config,
}
26 changes: 26 additions & 0 deletions crates/cdk/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ async fn main() -> anyhow::Result<()> {
cli::Commands::Node { config, components } => node(config, components)?,
cli::Commands::Erigon { config, chain } => erigon(config, chain).await?,
cli::Commands::Versions {} => versions::versions(),
cli::Commands::Config {} => config()?,
}

Ok(())
Expand Down Expand Up @@ -182,3 +183,28 @@ async fn get_timestamp(url: Url) -> Result<u64, anyhow::Error> {
struct Batch {
timestamp: String,
}

/// This function simply calls the config subcommand in cdk-node.
pub fn config() -> anyhow::Result<()> {
// This is to find the binary when running in development mode
// otherwise it will use system path
let bin_path = helpers::get_bin_path();

// Run the node passing the config file path as argument
let mut command = Command::new(bin_path.clone());
command.args(&["config"]);

let output_result = command.execute_output();
match output_result {
Ok(output) => output,
Err(e) => {
eprintln!(
"Failed to execute command, trying to find executable in path: {}",
bin_path
);
return Err(e.into());
}
};

Ok(())
}

0 comments on commit 45ab109

Please sign in to comment.