From 1ccc817752b020ff7d7b9651e53a7a8ccbe1d6d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Turmel?= Date: Thu, 3 Jul 2025 15:36:45 +0200 Subject: [PATCH 1/6] refactor(client-cli): move json boolean to commandContext and remove sharedArgs --- mithril-client-cli/src/command_context.rs | 10 +++ .../src/commands/cardano_db/download/mod.rs | 70 +++++++++---------- .../src/commands/cardano_db/download/v1.rs | 25 ++++--- .../src/commands/cardano_db/download/v2.rs | 26 ++++--- .../src/commands/cardano_db/list.rs | 24 ++----- .../src/commands/cardano_db/mod.rs | 8 +-- .../src/commands/cardano_db/show.rs | 24 ++----- .../src/commands/cardano_db/verify.rs | 28 +++----- .../cardano_stake_distribution/download.rs | 14 +--- .../cardano_stake_distribution/list.rs | 17 +---- .../commands/cardano_transaction/certify.rs | 14 +--- .../cardano_transaction/snapshot_list.rs | 14 +--- .../cardano_transaction/snapshot_show.rs | 14 +--- .../mithril_stake_distribution/download.rs | 14 +--- .../mithril_stake_distribution/list.rs | 17 +---- mithril-client-cli/src/commands/mod.rs | 9 --- mithril-client-cli/src/main.rs | 5 +- 17 files changed, 122 insertions(+), 211 deletions(-) diff --git a/mithril-client-cli/src/command_context.rs b/mithril-client-cli/src/command_context.rs index 82297549d4d..f08b8b8d8a4 100644 --- a/mithril-client-cli/src/command_context.rs +++ b/mithril-client-cli/src/command_context.rs @@ -12,6 +12,7 @@ use crate::configuration::ConfigParameters; pub struct CommandContext { config_builder: ConfigBuilder, unstable_enabled: bool, + json: bool, logger: Logger, } @@ -20,11 +21,13 @@ impl CommandContext { pub fn new( config_builder: ConfigBuilder, unstable_enabled: bool, + json: bool, logger: Logger, ) -> Self { Self { config_builder, unstable_enabled, + json, logger, } } @@ -34,6 +37,11 @@ impl CommandContext { self.unstable_enabled } + /// Check if JSON output is enabled + pub fn is_json_output_enabled(&self) -> bool { + self.json + } + /// Ensure that unstable commands are enabled pub fn require_unstable( &self, @@ -76,6 +84,7 @@ mod tests { let context = CommandContext::new( ConfigBuilder::default(), unstable_enabled, + true, Logger::root(slog::Discard, o!()), ); @@ -89,6 +98,7 @@ mod tests { let context = CommandContext::new( ConfigBuilder::default(), unstable_enabled, + true, Logger::root(slog::Discard, o!()), ); diff --git a/mithril-client-cli/src/commands/cardano_db/download/mod.rs b/mithril-client-cli/src/commands/cardano_db/download/mod.rs index 5d0258b49ee..b579ee9de66 100644 --- a/mithril-client-cli/src/commands/cardano_db/download/mod.rs +++ b/mithril-client-cli/src/commands/cardano_db/download/mod.rs @@ -9,7 +9,6 @@ use std::{collections::HashMap, path::PathBuf}; use crate::{ CommandContext, - commands::SharedArgs, commands::cardano_db::CardanoDbCommandsBackend, configuration::{ConfigError, ConfigParameters, ConfigSource}, utils::{self, JSON_CAUTION_KEY}, @@ -24,9 +23,6 @@ pub struct CardanoDbDownloadCommand { #[arg(short, long, value_enum, default_value_t)] backend: CardanoDbCommandsBackend, - #[clap(flatten)] - shared_args: SharedArgs, - /// Digest of the Cardano db snapshot to download or `latest` for the latest artifact /// /// Use the `list` command to get that information. @@ -74,41 +70,40 @@ pub struct CardanoDbDownloadCommand { } impl CardanoDbDownloadCommand { - fn is_json_output_enabled(&self) -> bool { - self.shared_args.json - } - /// Command execution pub async fn execute(&self, context: CommandContext) -> MithrilResult<()> { let params = context.config_parameters()?.add_source(self)?; match self.backend { CardanoDbCommandsBackend::V1 => { - let prepared_command = self.prepare_v1(¶ms)?; - prepared_command.execute(context.logger(), params).await + let prepared_command = self.prepare_v1(¶ms, &context)?; + prepared_command.execute(&context, params).await } CardanoDbCommandsBackend::V2 => { - let prepared_command = self.prepare_v2(¶ms)?; - prepared_command.execute(context.logger(), params).await + let prepared_command = self.prepare_v2(¶ms, &context)?; + prepared_command.execute(&context, params).await } } } - fn prepare_v1(&self, params: &ConfigParameters) -> MithrilResult { + fn prepare_v1( + &self, + params: &ConfigParameters, + context: &CommandContext, + ) -> MithrilResult { if self.allow_override || self.start.is_some() || self.end.is_some() { - self.warn_unused_parameter_with_v1_backend(); + self.warn_unused_parameter_with_v1_backend(context); } let ancillary_verification_key = if self.include_ancillary { - self.warn_ancillary_not_signed_by_mithril(); + self.warn_ancillary_not_signed_by_mithril(context); Some(params.require("ancillary_verification_key")?) } else { - self.warn_fast_bootstrap_not_available(); + self.warn_fast_bootstrap_not_available(context); None }; Ok(PreparedCardanoDbV1Download { - shared_args: self.shared_args.clone(), digest: self.digest.clone(), download_dir: params.require("download_dir")?, include_ancillary: self.include_ancillary, @@ -116,17 +111,20 @@ impl CardanoDbDownloadCommand { }) } - fn prepare_v2(&self, params: &ConfigParameters) -> MithrilResult { + fn prepare_v2( + &self, + params: &ConfigParameters, + context: &CommandContext, + ) -> MithrilResult { let ancillary_verification_key = if self.include_ancillary { - self.warn_ancillary_not_signed_by_mithril(); + self.warn_ancillary_not_signed_by_mithril(context); Some(params.require("ancillary_verification_key")?) } else { - self.warn_fast_bootstrap_not_available(); + self.warn_fast_bootstrap_not_available(context); None }; Ok(PreparedCardanoDbV2Download { - shared_args: self.shared_args.clone(), hash: self.digest.clone(), download_dir: params.require("download_dir")?, start: self.start, @@ -138,8 +136,8 @@ impl CardanoDbDownloadCommand { } /// Provides guidance on how to enable fast bootstrap by including ancillary files - fn warn_fast_bootstrap_not_available(&self) { - if self.is_json_output_enabled() { + fn warn_fast_bootstrap_not_available(&self, context: &CommandContext) { + if context.is_json_output_enabled() { let json = serde_json::json!({ JSON_CAUTION_KEY: "The fast bootstrap of the Cardano node is not available with the current parameters used in this command", "impact": "The ledger state will be recomputed from genesis at startup of the Cardano node", @@ -165,18 +163,18 @@ For more information, please refer to the network configuration page of the docu } } - fn warn_ancillary_not_signed_by_mithril(&self) { + fn warn_ancillary_not_signed_by_mithril(&self, context: &CommandContext) { let message = "Ancillary verification does not use the Mithril certification: as a mitigation, IOG owned keys are used to sign these files."; - if self.is_json_output_enabled() { + if context.is_json_output_enabled() { eprintln!(r#"{{"{JSON_CAUTION_KEY}":"{message}"}}"#); } else { eprintln!("{message}"); } } - fn warn_unused_parameter_with_v1_backend(&self) { + fn warn_unused_parameter_with_v1_backend(&self, context: &CommandContext) { let message = "`--start`, `--end`, and `--allow-override` are only available with the `v2` backend. They will be ignored."; - if self.is_json_output_enabled() { + if context.is_json_output_enabled() { eprintln!(r#"{{"{JSON_CAUTION_KEY}":"{message}"}}"#); } else { eprintln!("{message}"); @@ -227,7 +225,6 @@ mod tests { fn dummy_command() -> CardanoDbDownloadCommand { CardanoDbDownloadCommand { backend: Default::default(), - shared_args: SharedArgs { json: false }, digest: "whatever_digest".to_string(), download_dir: Some(std::path::PathBuf::from("whatever_dir")), genesis_verification_key: "whatever".to_string().into(), @@ -249,6 +246,7 @@ mod tests { let command_context = CommandContext::new( ConfigBuilder::default(), false, + true, Logger::root(slog::Discard, slog::o!()), ); @@ -274,14 +272,14 @@ mod tests { .set_default("ancillary_verification_key", "value from config") .expect("Failed to build config builder"); let command_context = - CommandContext::new(config, false, Logger::root(slog::Discard, slog::o!())); + CommandContext::new(config, false, true, Logger::root(slog::Discard, slog::o!())); let config_parameters = command_context .config_parameters() .unwrap() .add_source(&command) .unwrap(); - let result = command.prepare_v1(&config_parameters); + let result = command.prepare_v1(&config_parameters, &command_context); assert!(result.is_ok()); } @@ -292,9 +290,10 @@ mod tests { download_dir: None, ..dummy_command() }; - let command_context = CommandContext::new( + let command_context = &CommandContext::new( ConfigBuilder::default(), false, + true, Logger::root(slog::Discard, slog::o!()), ); let config_parameters = command_context @@ -303,7 +302,7 @@ mod tests { .add_source(&command) .unwrap(); - let result = command.prepare_v1(&config_parameters); + let result = command.prepare_v1(&config_parameters, command_context); assert!(result.is_err()); assert_eq!( @@ -326,14 +325,14 @@ mod tests { .set_default("ancillary_verification_key", "value from config") .expect("Failed to build config builder"); let command_context = - CommandContext::new(config, false, Logger::root(slog::Discard, slog::o!())); + CommandContext::new(config, false, true, Logger::root(slog::Discard, slog::o!())); let config_parameters = command_context .config_parameters() .unwrap() .add_source(&command) .unwrap(); - let result = command.prepare_v2(&config_parameters); + let result = command.prepare_v2(&config_parameters, &command_context); assert!(result.is_ok()); } @@ -347,6 +346,7 @@ mod tests { let command_context = CommandContext::new( ConfigBuilder::default(), false, + true, Logger::root(slog::Discard, slog::o!()), ); let config_parameters = command_context @@ -355,7 +355,7 @@ mod tests { .add_source(&command) .unwrap(); - let result = command.prepare_v2(&config_parameters); + let result = command.prepare_v2(&config_parameters, &command_context); assert!(result.is_err()); assert_eq!( diff --git a/mithril-client-cli/src/commands/cardano_db/download/v1.rs b/mithril-client-cli/src/commands/cardano_db/download/v1.rs index 9b67a1f5f63..ec24d055cf1 100644 --- a/mithril-client-cli/src/commands/cardano_db/download/v1.rs +++ b/mithril-client-cli/src/commands/cardano_db/download/v1.rs @@ -8,8 +8,8 @@ use mithril_client::{ }; use crate::{ + CommandContext, commands::{ - SharedArgs, cardano_db::{download::DB_DIRECTORY_NAME, shared_steps}, client_builder, }, @@ -22,7 +22,6 @@ use crate::{ #[derive(Debug, Clone)] pub(super) struct PreparedCardanoDbV1Download { - pub(super) shared_args: SharedArgs, pub(super) digest: String, pub(super) download_dir: String, pub(super) include_ancillary: bool, @@ -30,15 +29,15 @@ pub(super) struct PreparedCardanoDbV1Download { } impl PreparedCardanoDbV1Download { - fn is_json_output_enabled(&self) -> bool { - self.shared_args.json - } - /// Command execution - pub async fn execute(&self, logger: &Logger, params: ConfigParameters) -> MithrilResult<()> { + pub async fn execute( + &self, + context: &CommandContext, + params: ConfigParameters, + ) -> MithrilResult<()> { let db_dir = Path::new(&self.download_dir).join(DB_DIRECTORY_NAME); - let progress_output_type = if self.is_json_output_enabled() { + let progress_output_type = if context.is_json_output_enabled() { ProgressOutputType::JsonReporter } else { ProgressOutputType::Tty @@ -47,10 +46,10 @@ impl PreparedCardanoDbV1Download { let client = client_builder(¶ms)? .add_feedback_receiver(Arc::new(IndicatifFeedbackReceiver::new( progress_output_type, - logger.clone(), + context.logger().clone(), ))) .set_ancillary_verification_key(self.ancillary_verification_key.clone()) - .with_logger(logger.clone()) + .with_logger(context.logger().clone()) .build()?; let get_list_of_artifact_ids = || async { @@ -84,7 +83,7 @@ impl PreparedCardanoDbV1Download { .await?; Self::download_and_unpack_cardano_db( - logger, + context.logger(), 3, &progress_printer, client.cardano_database(), @@ -104,7 +103,7 @@ impl PreparedCardanoDbV1Download { Self::compute_cardano_db_message(4, &progress_printer, &certificate, &db_dir).await?; Self::verify_cardano_db_signature( - logger, + context.logger(), 5, &progress_printer, &certificate, @@ -119,7 +118,7 @@ impl PreparedCardanoDbV1Download { &cardano_db_message.digest, &cardano_db_message.network, &cardano_db_message.cardano_node_version, - self.is_json_output_enabled(), + context.is_json_output_enabled(), self.include_ancillary, )?; diff --git a/mithril-client-cli/src/commands/cardano_db/download/v2.rs b/mithril-client-cli/src/commands/cardano_db/download/v2.rs index df98bd77e35..774d4a539ad 100644 --- a/mithril-client-cli/src/commands/cardano_db/download/v2.rs +++ b/mithril-client-cli/src/commands/cardano_db/download/v2.rs @@ -13,8 +13,8 @@ use mithril_client::{ }; use crate::{ + CommandContext, commands::{ - SharedArgs, cardano_db::{download::DB_DIRECTORY_NAME, shared_steps}, client_builder, }, @@ -36,7 +36,6 @@ struct RestorationOptions { #[derive(Debug, Clone)] pub(super) struct PreparedCardanoDbV2Download { - pub(super) shared_args: SharedArgs, pub(super) hash: String, pub(super) download_dir: String, pub(super) start: Option, @@ -47,7 +46,11 @@ pub(super) struct PreparedCardanoDbV2Download { } impl PreparedCardanoDbV2Download { - pub async fn execute(&self, logger: &Logger, params: ConfigParameters) -> MithrilResult<()> { + pub async fn execute( + &self, + context: &CommandContext, + params: ConfigParameters, + ) -> MithrilResult<()> { let restoration_options = RestorationOptions { db_dir: Path::new(&self.download_dir).join(DB_DIRECTORY_NAME), immutable_file_range: shared_steps::immutable_file_range(self.start, self.end), @@ -59,7 +62,7 @@ impl PreparedCardanoDbV2Download { disk_space_safety_margin_ratio: DISK_SPACE_SAFETY_MARGIN_RATIO, }; - let progress_output_type = if self.is_json_output_enabled() { + let progress_output_type = if context.is_json_output_enabled() { ProgressOutputType::JsonReporter } else { ProgressOutputType::Tty @@ -68,10 +71,10 @@ impl PreparedCardanoDbV2Download { let client = client_builder(¶ms)? .add_feedback_receiver(Arc::new(IndicatifFeedbackReceiver::new( progress_output_type, - logger.clone(), + context.logger().clone(), ))) .set_ancillary_verification_key(self.ancillary_verification_key.clone()) - .with_logger(logger.clone()) + .with_logger(context.logger().clone()) .build()?; let get_list_of_artifact_ids = || async { @@ -111,7 +114,7 @@ impl PreparedCardanoDbV2Download { .await?; Self::download_and_unpack_cardano_database_snapshot( - logger, + context.logger(), 3, &progress_printer, client.cardano_database_v2(), @@ -146,7 +149,7 @@ impl PreparedCardanoDbV2Download { .await?; shared_steps::verify_message_matches_certificate( - logger, + context.logger(), 6, &progress_printer, &certificate, @@ -161,18 +164,13 @@ impl PreparedCardanoDbV2Download { &cardano_db_message.hash, &cardano_db_message.network, &cardano_db_message.cardano_node_version, - self.is_json_output_enabled(), + context.is_json_output_enabled(), restoration_options.download_unpack_options.include_ancillary, )?; Ok(()) } - /// Is JSON output enabled - pub fn is_json_output_enabled(&self) -> bool { - self.shared_args.json - } - fn compute_total_immutables_restored_size( cardano_db: &CardanoDatabaseSnapshot, restoration_options: &RestorationOptions, diff --git a/mithril-client-cli/src/commands/cardano_db/list.rs b/mithril-client-cli/src/commands/cardano_db/list.rs index ddfe453c676..82cd5604849 100644 --- a/mithril-client-cli/src/commands/cardano_db/list.rs +++ b/mithril-client-cli/src/commands/cardano_db/list.rs @@ -3,9 +3,7 @@ use cli_table::{Cell, Table, format::Justify, print_stdout}; use crate::{ CommandContext, - commands::{ - SharedArgs, cardano_db::CardanoDbCommandsBackend, client_builder_with_fallback_genesis_key, - }, + commands::{cardano_db::CardanoDbCommandsBackend, client_builder_with_fallback_genesis_key}, utils::CardanoDbUtils, }; use mithril_client::{Client, MithrilResult}; @@ -15,17 +13,9 @@ use mithril_client::{Client, MithrilResult}; pub struct CardanoDbListCommand { #[arg(short, long, value_enum, default_value_t)] backend: CardanoDbCommandsBackend, - - #[clap(flatten)] - shared_args: SharedArgs, } impl CardanoDbListCommand { - /// Is JSON output enabled - pub fn is_json_output_enabled(&self) -> bool { - self.shared_args.json - } - /// Main command execution pub async fn execute(&self, context: CommandContext) -> MithrilResult<()> { let params = context.config_parameters()?; @@ -34,17 +24,17 @@ impl CardanoDbListCommand { .build()?; match self.backend { - CardanoDbCommandsBackend::V1 => self.print_v1(client).await?, - CardanoDbCommandsBackend::V2 => self.print_v2(client).await?, + CardanoDbCommandsBackend::V1 => self.print_v1(client, context).await?, + CardanoDbCommandsBackend::V2 => self.print_v2(client, context).await?, } Ok(()) } - async fn print_v1(&self, client: Client) -> MithrilResult<()> { + async fn print_v1(&self, client: Client, context: CommandContext) -> MithrilResult<()> { let items = client.cardano_database().list().await?; - if self.is_json_output_enabled() { + if context.is_json_output_enabled() { println!("{}", serde_json::to_string(&items)?); } else { let items = items @@ -76,10 +66,10 @@ impl CardanoDbListCommand { Ok(()) } - async fn print_v2(&self, client: Client) -> MithrilResult<()> { + async fn print_v2(&self, client: Client, context: CommandContext) -> MithrilResult<()> { let items = client.cardano_database_v2().list().await?; - if self.is_json_output_enabled() { + if context.is_json_output_enabled() { println!("{}", serde_json::to_string(&items)?); } else { let items = items diff --git a/mithril-client-cli/src/commands/cardano_db/mod.rs b/mithril-client-cli/src/commands/cardano_db/mod.rs index d1db0c6f824..7b51c8e7a82 100644 --- a/mithril-client-cli/src/commands/cardano_db/mod.rs +++ b/mithril-client-cli/src/commands/cardano_db/mod.rs @@ -56,11 +56,11 @@ pub enum CardanoDbSnapshotCommands { impl CardanoDbCommands { /// Execute Cardano db command - pub async fn execute(&self, config_builder: CommandContext) -> MithrilResult<()> { + pub async fn execute(&self, context: CommandContext) -> MithrilResult<()> { match self { - Self::Download(cmd) => cmd.execute(config_builder).await, - Self::Snapshot(cmd) => cmd.execute(config_builder).await, - Self::Verify(cmd) => cmd.execute(config_builder).await, + Self::Download(cmd) => cmd.execute(context).await, + Self::Snapshot(cmd) => cmd.execute(context).await, + Self::Verify(cmd) => cmd.execute(context).await, } } } diff --git a/mithril-client-cli/src/commands/cardano_db/show.rs b/mithril-client-cli/src/commands/cardano_db/show.rs index 5e9643afde9..31b245bc4da 100644 --- a/mithril-client-cli/src/commands/cardano_db/show.rs +++ b/mithril-client-cli/src/commands/cardano_db/show.rs @@ -9,18 +9,13 @@ use mithril_client::{ use crate::{ CommandContext, - commands::{ - SharedArgs, cardano_db::CardanoDbCommandsBackend, client_builder_with_fallback_genesis_key, - }, + commands::{cardano_db::CardanoDbCommandsBackend, client_builder_with_fallback_genesis_key}, utils::{CardanoDbUtils, ExpanderUtils}, }; /// Clap command to show a given Cardano db #[derive(Parser, Debug, Clone)] pub struct CardanoDbShowCommand { - #[clap(flatten)] - shared_args: SharedArgs, - #[arg(short, long, value_enum, default_value_t)] backend: CardanoDbCommandsBackend, @@ -29,11 +24,6 @@ pub struct CardanoDbShowCommand { } impl CardanoDbShowCommand { - /// Is JSON output enabled - pub fn is_json_output_enabled(&self) -> bool { - self.shared_args.json - } - /// Cardano DB Show command pub async fn execute(&self, context: CommandContext) -> MithrilResult<()> { let params = context.config_parameters()?; @@ -42,14 +32,14 @@ impl CardanoDbShowCommand { .build()?; match self.backend { - CardanoDbCommandsBackend::V1 => self.print_v1(client).await?, - CardanoDbCommandsBackend::V2 => self.print_v2(client).await?, + CardanoDbCommandsBackend::V1 => self.print_v1(client, &context).await?, + CardanoDbCommandsBackend::V2 => self.print_v2(client, &context).await?, } Ok(()) } - async fn print_v1(&self, client: Client) -> MithrilResult<()> { + async fn print_v1(&self, client: Client, context: &CommandContext) -> MithrilResult<()> { let get_list_of_artifact_ids = || async { let cardano_dbs = client.cardano_database().list().await.with_context(|| { "Can not get the list of artifacts while retrieving the latest cardano db digest" @@ -70,7 +60,7 @@ impl CardanoDbShowCommand { .await? .ok_or_else(|| anyhow!("Cardano DB not found for digest: '{}'", &self.digest))?; - if self.is_json_output_enabled() { + if context.is_json_output_enabled() { println!("{}", serde_json::to_string(&cardano_db_message)?); } else { let cardano_db_table = vec![ @@ -104,7 +94,7 @@ impl CardanoDbShowCommand { Ok(()) } - async fn print_v2(&self, client: Client) -> MithrilResult<()> { + async fn print_v2(&self, client: Client, context: &CommandContext) -> MithrilResult<()> { let get_list_of_artifact_ids = || async { let cardano_dbs = client.cardano_database_v2().list().await.with_context(|| { "Can not get the list of artifacts while retrieving the latest cardano db snapshot hash" @@ -125,7 +115,7 @@ impl CardanoDbShowCommand { .await? .ok_or_else(|| anyhow!("Cardano DB snapshot not found for hash: '{}'", &self.digest))?; - if self.is_json_output_enabled() { + if context.is_json_output_enabled() { println!("{}", serde_json::to_string(&cardano_db_message)?); } else { let mut cardano_db_table = vec![ diff --git a/mithril-client-cli/src/commands/cardano_db/verify.rs b/mithril-client-cli/src/commands/cardano_db/verify.rs index 1dce73cc7d8..7d66b98890a 100644 --- a/mithril-client-cli/src/commands/cardano_db/verify.rs +++ b/mithril-client-cli/src/commands/cardano_db/verify.rs @@ -8,12 +8,10 @@ use anyhow::Context; use chrono::Utc; use clap::Parser; use mithril_client::MithrilResult; -use slog::Logger; use crate::{ CommandContext, commands::{ - SharedArgs, cardano_db::{CardanoDbCommandsBackend, shared_steps}, client_builder, }, @@ -27,9 +25,6 @@ pub struct CardanoDbVerifyCommand { #[arg(short, long, value_enum, default_value_t = CardanoDbCommandsBackend::V2)] backend: CardanoDbCommandsBackend, - #[clap(flatten)] - shared_args: SharedArgs, - /// Digest of the Cardano db snapshot to verify or `latest` for the latest artifact /// /// Use the `list` command to get that information. @@ -45,11 +40,6 @@ pub struct CardanoDbVerifyCommand { } impl CardanoDbVerifyCommand { - /// Is JSON output enabled - pub fn is_json_output_enabled(&self) -> bool { - self.shared_args.json - } - /// Main command execution pub async fn execute(&self, context: CommandContext) -> MithrilResult<()> { match self.backend { @@ -58,16 +48,20 @@ impl CardanoDbVerifyCommand { )), CardanoDbCommandsBackend::V2 => { let params = context.config_parameters()?.add_source(self)?; - self.verify(context.logger(), params).await + self.verify(&context, params).await } } } - async fn verify(&self, logger: &Logger, params: ConfigParameters) -> MithrilResult<()> { + async fn verify( + &self, + context: &CommandContext, + params: ConfigParameters, + ) -> MithrilResult<()> { let db_dir = params.require("db_dir")?; let db_dir = Path::new(&db_dir); - let progress_output_type = if self.is_json_output_enabled() { + let progress_output_type = if context.is_json_output_enabled() { ProgressOutputType::JsonReporter } else { ProgressOutputType::Tty @@ -76,9 +70,9 @@ impl CardanoDbVerifyCommand { let client = client_builder(¶ms)? .add_feedback_receiver(Arc::new(IndicatifFeedbackReceiver::new( progress_output_type, - logger.clone(), + context.logger().clone(), ))) - .with_logger(logger.clone()) + .with_logger(context.logger().clone()) .build()?; client.cardano_database_v2().check_has_immutables(db_dir)?; @@ -133,7 +127,7 @@ impl CardanoDbVerifyCommand { .await?; shared_steps::verify_message_matches_certificate( - logger, + &context.logger().clone(), 4, &progress_printer, &certificate, @@ -146,7 +140,7 @@ impl CardanoDbVerifyCommand { Self::log_verified_information( db_dir, &cardano_db_message.hash, - self.is_json_output_enabled(), + context.is_json_output_enabled(), )?; Ok(()) diff --git a/mithril-client-cli/src/commands/cardano_stake_distribution/download.rs b/mithril-client-cli/src/commands/cardano_stake_distribution/download.rs index 6467052be23..b04d7f1df66 100644 --- a/mithril-client-cli/src/commands/cardano_stake_distribution/download.rs +++ b/mithril-client-cli/src/commands/cardano_stake_distribution/download.rs @@ -11,7 +11,7 @@ use crate::utils::{ }; use crate::{ CommandContext, - commands::{SharedArgs, client_builder}, + commands::client_builder, configuration::{ConfigError, ConfigSource}, }; use mithril_client::Client; @@ -21,9 +21,6 @@ use mithril_client::{CardanoStakeDistribution, MessageBuilder, MithrilResult}; /// Download and verify a Cardano stake distribution information. #[derive(Parser, Debug, Clone)] pub struct CardanoStakeDistributionDownloadCommand { - #[clap(flatten)] - shared_args: SharedArgs, - /// Hash or Epoch of the Cardano stake distribution artifact, or `latest` for the latest artifact. /// /// The epoch represents the epoch at the end of which the Cardano stake distribution is computed by the Cardano node. @@ -39,11 +36,6 @@ pub struct CardanoStakeDistributionDownloadCommand { } impl CardanoStakeDistributionDownloadCommand { - /// Is JSON output enabled - pub fn is_json_output_enabled(&self) -> bool { - self.shared_args.json - } - /// Main command execution pub async fn execute(&self, context: CommandContext) -> MithrilResult<()> { let params = context.config_parameters()?.add_source(self)?; @@ -51,7 +43,7 @@ impl CardanoStakeDistributionDownloadCommand { let download_dir = Path::new(&download_dir); let logger = context.logger(); - let progress_output_type = if self.is_json_output_enabled() { + let progress_output_type = if context.is_json_output_enabled() { ProgressOutputType::JsonReporter } else { ProgressOutputType::Tty @@ -135,7 +127,7 @@ impl CardanoStakeDistributionDownloadCommand { })?, )?; - if self.is_json_output_enabled() { + if context.is_json_output_enabled() { println!( r#"{{"cardano_stake_distribution_epoch": "{}", "filepath": "{}"}}"#, cardano_stake_distribution.epoch, diff --git a/mithril-client-cli/src/commands/cardano_stake_distribution/list.rs b/mithril-client-cli/src/commands/cardano_stake_distribution/list.rs index da76b61cc60..291842702bd 100644 --- a/mithril-client-cli/src/commands/cardano_stake_distribution/list.rs +++ b/mithril-client-cli/src/commands/cardano_stake_distribution/list.rs @@ -1,25 +1,14 @@ use clap::Parser; use cli_table::{Cell, Table, format::Justify, print_stdout}; -use crate::{ - CommandContext, - commands::{SharedArgs, client_builder_with_fallback_genesis_key}, -}; +use crate::{CommandContext, commands::client_builder_with_fallback_genesis_key}; use mithril_client::MithrilResult; /// Cardano stake distribution LIST command #[derive(Parser, Debug, Clone)] -pub struct CardanoStakeDistributionListCommand { - #[clap(flatten)] - shared_args: SharedArgs, -} +pub struct CardanoStakeDistributionListCommand {} impl CardanoStakeDistributionListCommand { - /// Is JSON output enabled - pub fn is_json_output_enabled(&self) -> bool { - self.shared_args.json - } - /// Main command execution pub async fn execute(&self, context: CommandContext) -> MithrilResult<()> { let params = context.config_parameters()?; @@ -28,7 +17,7 @@ impl CardanoStakeDistributionListCommand { .build()?; let lines = client.cardano_stake_distribution().list().await?; - if self.is_json_output_enabled() { + if context.is_json_output_enabled() { println!("{}", serde_json::to_string(&lines)?); } else { let lines = lines diff --git a/mithril-client-cli/src/commands/cardano_transaction/certify.rs b/mithril-client-cli/src/commands/cardano_transaction/certify.rs index 4a37797c95b..34431b3f04d 100644 --- a/mithril-client-cli/src/commands/cardano_transaction/certify.rs +++ b/mithril-client-cli/src/commands/cardano_transaction/certify.rs @@ -12,16 +12,13 @@ use mithril_client::{ use crate::utils::{IndicatifFeedbackReceiver, ProgressOutputType, ProgressPrinter}; use crate::{ CommandContext, - commands::{SharedArgs, client_builder}, + commands::client_builder, configuration::{ConfigError, ConfigSource}, }; /// Clap command to show a given Cardano transaction sets #[derive(Parser, Debug, Clone)] pub struct CardanoTransactionsCertifyCommand { - #[clap(flatten)] - shared_args: SharedArgs, - /// Genesis verification key to check the certificate chain. #[clap(long, env = "GENESIS_VERIFICATION_KEY")] genesis_verification_key: Option, @@ -32,17 +29,12 @@ pub struct CardanoTransactionsCertifyCommand { } impl CardanoTransactionsCertifyCommand { - /// Is JSON output enabled - pub fn is_json_output_enabled(&self) -> bool { - self.shared_args.json - } - /// Cardano transaction certify command pub async fn execute(&self, context: CommandContext) -> MithrilResult<()> { let params = context.config_parameters()?.add_source(self)?; let logger = context.logger(); - let progress_output_type = if self.is_json_output_enabled() { + let progress_output_type = if context.is_json_output_enabled() { ProgressOutputType::JsonReporter } else { ProgressOutputType::Tty @@ -97,7 +89,7 @@ impl CardanoTransactionsCertifyCommand { Self::log_certify_information( &verified_transactions, &cardano_transaction_proof.non_certified_transactions, - self.is_json_output_enabled(), + context.is_json_output_enabled(), ) } diff --git a/mithril-client-cli/src/commands/cardano_transaction/snapshot_list.rs b/mithril-client-cli/src/commands/cardano_transaction/snapshot_list.rs index b01081dd2ba..00f052e53d8 100644 --- a/mithril-client-cli/src/commands/cardano_transaction/snapshot_list.rs +++ b/mithril-client-cli/src/commands/cardano_transaction/snapshot_list.rs @@ -3,22 +3,14 @@ use cli_table::format::Justify; use cli_table::{Cell, Table, print_stdout}; use crate::CommandContext; -use crate::commands::{SharedArgs, client_builder_with_fallback_genesis_key}; +use crate::commands::client_builder_with_fallback_genesis_key; use mithril_client::MithrilResult; /// Cardano transaction snapshot list command #[derive(Parser, Debug, Clone)] -pub struct CardanoTransactionSnapshotListCommand { - #[clap(flatten)] - shared_args: SharedArgs, -} +pub struct CardanoTransactionSnapshotListCommand {} impl CardanoTransactionSnapshotListCommand { - /// Is JSON output enabled - pub fn is_json_output_enabled(&self) -> bool { - self.shared_args.json - } - /// Main command execution pub async fn execute(&self, context: CommandContext) -> MithrilResult<()> { let params = context.config_parameters()?; @@ -27,7 +19,7 @@ impl CardanoTransactionSnapshotListCommand { .build()?; let lines = client.cardano_transaction().list_snapshots().await?; - if self.is_json_output_enabled() { + if context.is_json_output_enabled() { println!("{}", serde_json::to_string(&lines)?); } else { let lines = lines diff --git a/mithril-client-cli/src/commands/cardano_transaction/snapshot_show.rs b/mithril-client-cli/src/commands/cardano_transaction/snapshot_show.rs index a89932f2981..470b54b8ad8 100644 --- a/mithril-client-cli/src/commands/cardano_transaction/snapshot_show.rs +++ b/mithril-client-cli/src/commands/cardano_transaction/snapshot_show.rs @@ -3,28 +3,18 @@ use clap::Parser; use cli_table::{Cell, Table, print_stdout}; use crate::{ - CommandContext, - commands::{SharedArgs, client_builder_with_fallback_genesis_key}, - utils::ExpanderUtils, + CommandContext, commands::client_builder_with_fallback_genesis_key, utils::ExpanderUtils, }; use mithril_client::MithrilResult; /// Clap command to show a given Cardano transaction snapshot #[derive(Parser, Debug, Clone)] pub struct CardanoTransactionsSnapshotShowCommand { - #[clap(flatten)] - shared_args: SharedArgs, - /// Hash of the Cardano transaction snapshot to show or `latest` for the latest artifact hash: String, } impl CardanoTransactionsSnapshotShowCommand { - /// Is JSON output enabled - pub fn is_json_output_enabled(&self) -> bool { - self.shared_args.json - } - /// Cardano transaction snapshot Show command pub async fn execute(&self, context: CommandContext) -> MithrilResult<()> { let params = context.config_parameters()?; @@ -57,7 +47,7 @@ impl CardanoTransactionsSnapshotShowCommand { ) })?; - if self.is_json_output_enabled() { + if context.is_json_output_enabled() { println!("{}", serde_json::to_string(&tx_sets)?); } else { let transaction_sets_table = vec![ diff --git a/mithril-client-cli/src/commands/mithril_stake_distribution/download.rs b/mithril-client-cli/src/commands/mithril_stake_distribution/download.rs index db206a51af6..4a002a6a015 100644 --- a/mithril-client-cli/src/commands/mithril_stake_distribution/download.rs +++ b/mithril-client-cli/src/commands/mithril_stake_distribution/download.rs @@ -9,7 +9,7 @@ use std::{ use crate::utils::{self, IndicatifFeedbackReceiver, ProgressOutputType, ProgressPrinter}; use crate::{ CommandContext, - commands::{SharedArgs, client_builder}, + commands::client_builder, configuration::{ConfigError, ConfigSource}, utils::ExpanderUtils, }; @@ -20,9 +20,6 @@ use mithril_client::MithrilResult; /// verification fails, the file is not persisted. #[derive(Parser, Debug, Clone)] pub struct MithrilStakeDistributionDownloadCommand { - #[clap(flatten)] - shared_args: SharedArgs, - /// Hash of the Mithril stake distribution artifact, or `latest` for the latest artifact. artifact_hash: String, @@ -39,11 +36,6 @@ pub struct MithrilStakeDistributionDownloadCommand { } impl MithrilStakeDistributionDownloadCommand { - /// Is JSON output enabled - pub fn is_json_output_enabled(&self) -> bool { - self.shared_args.json - } - /// Main command execution pub async fn execute(&self, context: CommandContext) -> MithrilResult<()> { let params = context.config_parameters()?.add_source(self)?; @@ -51,7 +43,7 @@ impl MithrilStakeDistributionDownloadCommand { let download_dir = Path::new(&download_dir); let logger = context.logger(); - let progress_output_type = if self.is_json_output_enabled() { + let progress_output_type = if context.is_json_output_enabled() { ProgressOutputType::JsonReporter } else { ProgressOutputType::Tty @@ -149,7 +141,7 @@ impl MithrilStakeDistributionDownloadCommand { })?, )?; - if self.is_json_output_enabled() { + if context.is_json_output_enabled() { println!( r#"{{"mithril_stake_distribution_hash": "{}", "filepath": "{}"}}"#, mithril_stake_distribution.hash, diff --git a/mithril-client-cli/src/commands/mithril_stake_distribution/list.rs b/mithril-client-cli/src/commands/mithril_stake_distribution/list.rs index 517928fd9e2..74680627c17 100644 --- a/mithril-client-cli/src/commands/mithril_stake_distribution/list.rs +++ b/mithril-client-cli/src/commands/mithril_stake_distribution/list.rs @@ -1,25 +1,14 @@ use clap::Parser; use cli_table::{Cell, Table, format::Justify, print_stdout}; -use crate::{ - CommandContext, - commands::{SharedArgs, client_builder_with_fallback_genesis_key}, -}; +use crate::{CommandContext, commands::client_builder_with_fallback_genesis_key}; use mithril_client::MithrilResult; /// Mithril stake distribution LIST command #[derive(Parser, Debug, Clone)] -pub struct MithrilStakeDistributionListCommand { - #[clap(flatten)] - shared_args: SharedArgs, -} +pub struct MithrilStakeDistributionListCommand {} impl MithrilStakeDistributionListCommand { - /// Is JSON output enabled - pub fn is_json_output_enabled(&self) -> bool { - self.shared_args.json - } - /// Main command execution pub async fn execute(&self, context: CommandContext) -> MithrilResult<()> { let params = context.config_parameters()?; @@ -28,7 +17,7 @@ impl MithrilStakeDistributionListCommand { .build()?; let lines = client.mithril_stake_distribution().list().await?; - if self.is_json_output_enabled() { + if context.is_json_output_enabled() { println!("{}", serde_json::to_string(&lines)?); } else { let lines = lines diff --git a/mithril-client-cli/src/commands/mod.rs b/mithril-client-cli/src/commands/mod.rs index 030afcfda77..56b41553fcc 100644 --- a/mithril-client-cli/src/commands/mod.rs +++ b/mithril-client-cli/src/commands/mod.rs @@ -12,21 +12,12 @@ pub mod tools; pub use deprecation::{DeprecatedCommand, Deprecation}; -use clap::Args; use mithril_client::{ClientBuilder, MithrilResult}; use crate::configuration::ConfigParameters; const CLIENT_TYPE_CLI: &str = "CLI"; -/// Shared arguments for all commands -#[derive(Debug, Clone, Args)] -pub struct SharedArgs { - /// Enable JSON output for command results - #[clap(long)] - json: bool, -} - pub(crate) fn client_builder(params: &ConfigParameters) -> MithrilResult { let builder = ClientBuilder::aggregator( ¶ms.require("aggregator_endpoint")?, diff --git a/mithril-client-cli/src/main.rs b/mithril-client-cli/src/main.rs index 2c9a64859b0..9a2805a02e6 100644 --- a/mithril-client-cli/src/main.rs +++ b/mithril-client-cli/src/main.rs @@ -86,6 +86,9 @@ pub struct Args { /// Request origin tag #[clap(long)] origin_tag: Option, + + #[clap(long, global = true)] + json: bool, } impl Args { @@ -102,7 +105,7 @@ impl Args { .add_source(config::File::with_name(&filename).required(false)) .add_source(self.clone()) .set_default("download_dir", "")?; - let context = CommandContext::new(config, self.unstable, root_logger); + let context = CommandContext::new(config, self.unstable, self.json, root_logger); self.command.execute(context).await } From 8fa02ff4406eac57e049ed48b3466bfe80cb5b14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Turmel?= Date: Thu, 3 Jul 2025 17:17:30 +0200 Subject: [PATCH 2/6] refactor(client-cli): use mutable ConfigParameter from CommandContext --- mithril-client-cli/src/command_context.rs | 64 ++++++++--- .../src/commands/cardano_db/download/mod.rs | 100 +++++++----------- .../src/commands/cardano_db/download/v1.rs | 9 +- .../src/commands/cardano_db/download/v2.rs | 9 +- .../src/commands/cardano_db/list.rs | 3 +- .../src/commands/cardano_db/show.rs | 3 +- .../src/commands/cardano_db/verify.rs | 18 ++-- .../cardano_stake_distribution/download.rs | 8 +- .../cardano_stake_distribution/list.rs | 3 +- .../commands/cardano_transaction/certify.rs | 6 +- .../cardano_transaction/snapshot_list.rs | 3 +- .../cardano_transaction/snapshot_show.rs | 3 +- .../mithril_stake_distribution/download.rs | 8 +- .../mithril_stake_distribution/list.rs | 3 +- mithril-client-cli/src/configuration.rs | 14 ++- mithril-client-cli/src/lib.rs | 1 + mithril-client-cli/src/main.rs | 35 +++--- 17 files changed, 150 insertions(+), 140 deletions(-) diff --git a/mithril-client-cli/src/command_context.rs b/mithril-client-cli/src/command_context.rs index f08b8b8d8a4..b5201c16cee 100644 --- a/mithril-client-cli/src/command_context.rs +++ b/mithril-client-cli/src/command_context.rs @@ -1,8 +1,5 @@ use anyhow::anyhow; -use config::ConfigBuilder; -use config::builder::DefaultState; use slog::Logger; -use std::collections::HashMap; use mithril_client::MithrilResult; @@ -10,7 +7,7 @@ use crate::configuration::ConfigParameters; /// Context for the command execution pub struct CommandContext { - config_builder: ConfigBuilder, + config_parameters: ConfigParameters, unstable_enabled: bool, json: bool, logger: Logger, @@ -19,13 +16,13 @@ pub struct CommandContext { impl CommandContext { /// Create a new command context pub fn new( - config_builder: ConfigBuilder, + config_parameters: ConfigParameters, unstable_enabled: bool, json: bool, logger: Logger, ) -> Self { Self { - config_builder, + config_parameters, unstable_enabled, json, logger, @@ -59,11 +56,14 @@ impl CommandContext { } } - /// Get the configured parameters - pub fn config_parameters(&self) -> MithrilResult { - let config = self.config_builder.clone().build()?; - let config_hash_map = config.try_deserialize::>()?; - Ok(ConfigParameters::new(config_hash_map)) + /// Get a reference to the configured parameters + pub fn config_parameters(&self) -> &ConfigParameters { + &self.config_parameters + } + + /// Get a mutable reference to the configured parameters + pub fn config_parameters_mut(&mut self) -> &mut ConfigParameters { + &mut self.config_parameters } /// Get the shared logger @@ -75,6 +75,9 @@ impl CommandContext { #[cfg(test)] mod tests { use slog::o; + use std::collections::HashMap; + + use crate::configuration::{ConfigError, ConfigSource}; use super::*; @@ -82,7 +85,7 @@ mod tests { fn require_unstable_return_ok_if_unstable_enabled() { let unstable_enabled = true; let context = CommandContext::new( - ConfigBuilder::default(), + ConfigParameters::default(), unstable_enabled, true, Logger::root(slog::Discard, o!()), @@ -96,7 +99,7 @@ mod tests { fn require_unstable_return_err_if_unstable_disabled() { let unstable_enabled = false; let context = CommandContext::new( - ConfigBuilder::default(), + ConfigParameters::default(), unstable_enabled, true, Logger::root(slog::Discard, o!()), @@ -105,4 +108,39 @@ mod tests { let result = context.require_unstable("test", None); assert!(result.is_err(), "Expected Err, got {result:?}"); } + + #[test] + fn can_edit_config_parameters() { + struct ParamSource { + key: String, + value: String, + } + impl ConfigSource for ParamSource { + fn collect(&self) -> Result, ConfigError> { + Ok(HashMap::from([(self.key.clone(), self.value.clone())])) + } + } + + let mut context = CommandContext::new( + ConfigParameters::default(), + false, + true, + Logger::root(slog::Discard, o!()), + ); + + assert_eq!(context.config_parameters_mut().get("key"), None,); + + context + .config_parameters_mut() + .add_source(&ParamSource { + key: "key".to_string(), + value: "value".to_string(), + }) + .unwrap(); + + assert_eq!( + context.config_parameters_mut().get("key"), + Some("value".to_string()) + ); + } } diff --git a/mithril-client-cli/src/commands/cardano_db/download/mod.rs b/mithril-client-cli/src/commands/cardano_db/download/mod.rs index b579ee9de66..a78fa1ee65f 100644 --- a/mithril-client-cli/src/commands/cardano_db/download/mod.rs +++ b/mithril-client-cli/src/commands/cardano_db/download/mod.rs @@ -10,7 +10,7 @@ use std::{collections::HashMap, path::PathBuf}; use crate::{ CommandContext, commands::cardano_db::CardanoDbCommandsBackend, - configuration::{ConfigError, ConfigParameters, ConfigSource}, + configuration::{ConfigError, ConfigSource}, utils::{self, JSON_CAUTION_KEY}, }; use mithril_client::{MithrilResult, common::ImmutableFileNumber}; @@ -71,33 +71,29 @@ pub struct CardanoDbDownloadCommand { impl CardanoDbDownloadCommand { /// Command execution - pub async fn execute(&self, context: CommandContext) -> MithrilResult<()> { - let params = context.config_parameters()?.add_source(self)?; + pub async fn execute(&self, mut context: CommandContext) -> MithrilResult<()> { + context.config_parameters_mut().add_source(self)?; match self.backend { CardanoDbCommandsBackend::V1 => { - let prepared_command = self.prepare_v1(¶ms, &context)?; - prepared_command.execute(&context, params).await + let prepared_command = self.prepare_v1(&context)?; + prepared_command.execute(&context).await } CardanoDbCommandsBackend::V2 => { - let prepared_command = self.prepare_v2(¶ms, &context)?; - prepared_command.execute(&context, params).await + let prepared_command = self.prepare_v2(&context)?; + prepared_command.execute(&context).await } } } - fn prepare_v1( - &self, - params: &ConfigParameters, - context: &CommandContext, - ) -> MithrilResult { + fn prepare_v1(&self, context: &CommandContext) -> MithrilResult { if self.allow_override || self.start.is_some() || self.end.is_some() { self.warn_unused_parameter_with_v1_backend(context); } let ancillary_verification_key = if self.include_ancillary { self.warn_ancillary_not_signed_by_mithril(context); - Some(params.require("ancillary_verification_key")?) + Some(context.config_parameters().require("ancillary_verification_key")?) } else { self.warn_fast_bootstrap_not_available(context); None @@ -105,20 +101,16 @@ impl CardanoDbDownloadCommand { Ok(PreparedCardanoDbV1Download { digest: self.digest.clone(), - download_dir: params.require("download_dir")?, + download_dir: context.config_parameters().require("download_dir")?, include_ancillary: self.include_ancillary, ancillary_verification_key, }) } - fn prepare_v2( - &self, - params: &ConfigParameters, - context: &CommandContext, - ) -> MithrilResult { + fn prepare_v2(&self, context: &CommandContext) -> MithrilResult { let ancillary_verification_key = if self.include_ancillary { self.warn_ancillary_not_signed_by_mithril(context); - Some(params.require("ancillary_verification_key")?) + Some(context.config_parameters().require("ancillary_verification_key")?) } else { self.warn_fast_bootstrap_not_available(context); None @@ -126,7 +118,7 @@ impl CardanoDbDownloadCommand { Ok(PreparedCardanoDbV2Download { hash: self.digest.clone(), - download_dir: params.require("download_dir")?, + download_dir: context.config_parameters().require("download_dir")?, start: self.start, end: self.end, include_ancillary: self.include_ancillary, @@ -217,9 +209,10 @@ impl ConfigSource for CardanoDbDownloadCommand { #[cfg(test)] mod tests { - use config::ConfigBuilder; use slog::Logger; + use crate::ConfigParameters; + use super::*; fn dummy_command() -> CardanoDbDownloadCommand { @@ -244,7 +237,7 @@ mod tests { ..dummy_command() }; let command_context = CommandContext::new( - ConfigBuilder::default(), + ConfigParameters::default(), false, true, Logger::root(slog::Discard, slog::o!()), @@ -268,18 +261,15 @@ mod tests { ancillary_verification_key: None, ..dummy_command() }; - let config = config::Config::builder() - .set_default("ancillary_verification_key", "value from config") - .expect("Failed to build config builder"); - let command_context = + let config = ConfigParameters::new(HashMap::from([( + "ancillary_verification_key".to_string(), + "value from config".to_string(), + )])); + let mut command_context = CommandContext::new(config, false, true, Logger::root(slog::Discard, slog::o!())); - let config_parameters = command_context - .config_parameters() - .unwrap() - .add_source(&command) - .unwrap(); + command_context.config_parameters_mut().add_source(&command).unwrap(); - let result = command.prepare_v1(&config_parameters, &command_context); + let result = command.prepare_v1(&command_context); assert!(result.is_ok()); } @@ -290,19 +280,16 @@ mod tests { download_dir: None, ..dummy_command() }; - let command_context = &CommandContext::new( - ConfigBuilder::default(), + let mut command_context = CommandContext::new( + ConfigParameters::default(), false, true, Logger::root(slog::Discard, slog::o!()), ); - let config_parameters = command_context - .config_parameters() - .unwrap() - .add_source(&command) - .unwrap(); - let result = command.prepare_v1(&config_parameters, command_context); + command_context.config_parameters_mut().add_source(&command).unwrap(); + + let result = command.prepare_v1(&command_context); assert!(result.is_err()); assert_eq!( @@ -321,18 +308,16 @@ mod tests { ancillary_verification_key: None, ..dummy_command() }; - let config = config::Config::builder() - .set_default("ancillary_verification_key", "value from config") - .expect("Failed to build config builder"); - let command_context = + let config = ConfigParameters::new(HashMap::from([( + "ancillary_verification_key".to_string(), + "value from config".to_string(), + )])); + let mut command_context = CommandContext::new(config, false, true, Logger::root(slog::Discard, slog::o!())); - let config_parameters = command_context - .config_parameters() - .unwrap() - .add_source(&command) - .unwrap(); - let result = command.prepare_v2(&config_parameters, &command_context); + command_context.config_parameters_mut().add_source(&command).unwrap(); + + let result = command.prepare_v2(&command_context); assert!(result.is_ok()); } @@ -343,19 +328,16 @@ mod tests { download_dir: None, ..dummy_command() }; - let command_context = CommandContext::new( - ConfigBuilder::default(), + let mut command_context = CommandContext::new( + ConfigParameters::default(), false, true, Logger::root(slog::Discard, slog::o!()), ); - let config_parameters = command_context - .config_parameters() - .unwrap() - .add_source(&command) - .unwrap(); - let result = command.prepare_v2(&config_parameters, &command_context); + command_context.config_parameters_mut().add_source(&command).unwrap(); + + let result = command.prepare_v2(&command_context); assert!(result.is_err()); assert_eq!( diff --git a/mithril-client-cli/src/commands/cardano_db/download/v1.rs b/mithril-client-cli/src/commands/cardano_db/download/v1.rs index ec24d055cf1..d37b7803180 100644 --- a/mithril-client-cli/src/commands/cardano_db/download/v1.rs +++ b/mithril-client-cli/src/commands/cardano_db/download/v1.rs @@ -13,7 +13,6 @@ use crate::{ cardano_db::{download::DB_DIRECTORY_NAME, shared_steps}, client_builder, }, - configuration::ConfigParameters, utils::{ CardanoDbDownloadChecker, CardanoDbUtils, ExpanderUtils, IndicatifFeedbackReceiver, ProgressOutputType, ProgressPrinter, @@ -30,11 +29,7 @@ pub(super) struct PreparedCardanoDbV1Download { impl PreparedCardanoDbV1Download { /// Command execution - pub async fn execute( - &self, - context: &CommandContext, - params: ConfigParameters, - ) -> MithrilResult<()> { + pub async fn execute(&self, context: &CommandContext) -> MithrilResult<()> { let db_dir = Path::new(&self.download_dir).join(DB_DIRECTORY_NAME); let progress_output_type = if context.is_json_output_enabled() { @@ -43,7 +38,7 @@ impl PreparedCardanoDbV1Download { ProgressOutputType::Tty }; let progress_printer = ProgressPrinter::new(progress_output_type, 5); - let client = client_builder(¶ms)? + let client = client_builder(context.config_parameters())? .add_feedback_receiver(Arc::new(IndicatifFeedbackReceiver::new( progress_output_type, context.logger().clone(), diff --git a/mithril-client-cli/src/commands/cardano_db/download/v2.rs b/mithril-client-cli/src/commands/cardano_db/download/v2.rs index 774d4a539ad..b054424947e 100644 --- a/mithril-client-cli/src/commands/cardano_db/download/v2.rs +++ b/mithril-client-cli/src/commands/cardano_db/download/v2.rs @@ -18,7 +18,6 @@ use crate::{ cardano_db::{download::DB_DIRECTORY_NAME, shared_steps}, client_builder, }, - configuration::ConfigParameters, utils::{ CardanoDbDownloadChecker, CardanoDbUtils, ExpanderUtils, IndicatifFeedbackReceiver, ProgressOutputType, ProgressPrinter, @@ -46,11 +45,7 @@ pub(super) struct PreparedCardanoDbV2Download { } impl PreparedCardanoDbV2Download { - pub async fn execute( - &self, - context: &CommandContext, - params: ConfigParameters, - ) -> MithrilResult<()> { + pub async fn execute(&self, context: &CommandContext) -> MithrilResult<()> { let restoration_options = RestorationOptions { db_dir: Path::new(&self.download_dir).join(DB_DIRECTORY_NAME), immutable_file_range: shared_steps::immutable_file_range(self.start, self.end), @@ -68,7 +63,7 @@ impl PreparedCardanoDbV2Download { ProgressOutputType::Tty }; let progress_printer = ProgressPrinter::new(progress_output_type, 6); - let client = client_builder(¶ms)? + let client = client_builder(context.config_parameters())? .add_feedback_receiver(Arc::new(IndicatifFeedbackReceiver::new( progress_output_type, context.logger().clone(), diff --git a/mithril-client-cli/src/commands/cardano_db/list.rs b/mithril-client-cli/src/commands/cardano_db/list.rs index 82cd5604849..1ab9b3adc9c 100644 --- a/mithril-client-cli/src/commands/cardano_db/list.rs +++ b/mithril-client-cli/src/commands/cardano_db/list.rs @@ -18,8 +18,7 @@ pub struct CardanoDbListCommand { impl CardanoDbListCommand { /// Main command execution pub async fn execute(&self, context: CommandContext) -> MithrilResult<()> { - let params = context.config_parameters()?; - let client = client_builder_with_fallback_genesis_key(¶ms)? + let client = client_builder_with_fallback_genesis_key(context.config_parameters())? .with_logger(context.logger().clone()) .build()?; diff --git a/mithril-client-cli/src/commands/cardano_db/show.rs b/mithril-client-cli/src/commands/cardano_db/show.rs index 31b245bc4da..63808db50b0 100644 --- a/mithril-client-cli/src/commands/cardano_db/show.rs +++ b/mithril-client-cli/src/commands/cardano_db/show.rs @@ -26,8 +26,7 @@ pub struct CardanoDbShowCommand { impl CardanoDbShowCommand { /// Cardano DB Show command pub async fn execute(&self, context: CommandContext) -> MithrilResult<()> { - let params = context.config_parameters()?; - let client = client_builder_with_fallback_genesis_key(¶ms)? + let client = client_builder_with_fallback_genesis_key(context.config_parameters())? .with_logger(context.logger().clone()) .build()?; diff --git a/mithril-client-cli/src/commands/cardano_db/verify.rs b/mithril-client-cli/src/commands/cardano_db/verify.rs index 7d66b98890a..6ecb5e85fb5 100644 --- a/mithril-client-cli/src/commands/cardano_db/verify.rs +++ b/mithril-client-cli/src/commands/cardano_db/verify.rs @@ -15,7 +15,7 @@ use crate::{ cardano_db::{CardanoDbCommandsBackend, shared_steps}, client_builder, }, - configuration::{ConfigError, ConfigParameters, ConfigSource}, + configuration::{ConfigError, ConfigSource}, utils::{self, ExpanderUtils, IndicatifFeedbackReceiver, ProgressOutputType, ProgressPrinter}, }; @@ -41,24 +41,20 @@ pub struct CardanoDbVerifyCommand { impl CardanoDbVerifyCommand { /// Main command execution - pub async fn execute(&self, context: CommandContext) -> MithrilResult<()> { + pub async fn execute(&self, mut context: CommandContext) -> MithrilResult<()> { match self.backend { CardanoDbCommandsBackend::V1 => Err(anyhow::anyhow!( r#"The "verify" subcommand is not available for the v1, use --backend v2 instead"#, )), CardanoDbCommandsBackend::V2 => { - let params = context.config_parameters()?.add_source(self)?; - self.verify(&context, params).await + context.config_parameters_mut().add_source(self)?; + self.verify(&context).await } } } - async fn verify( - &self, - context: &CommandContext, - params: ConfigParameters, - ) -> MithrilResult<()> { - let db_dir = params.require("db_dir")?; + async fn verify(&self, context: &CommandContext) -> MithrilResult<()> { + let db_dir = context.config_parameters().require("db_dir")?; let db_dir = Path::new(&db_dir); let progress_output_type = if context.is_json_output_enabled() { @@ -67,7 +63,7 @@ impl CardanoDbVerifyCommand { ProgressOutputType::Tty }; let progress_printer = ProgressPrinter::new(progress_output_type, 4); - let client = client_builder(¶ms)? + let client = client_builder(context.config_parameters())? .add_feedback_receiver(Arc::new(IndicatifFeedbackReceiver::new( progress_output_type, context.logger().clone(), diff --git a/mithril-client-cli/src/commands/cardano_stake_distribution/download.rs b/mithril-client-cli/src/commands/cardano_stake_distribution/download.rs index b04d7f1df66..8c5b54eb429 100644 --- a/mithril-client-cli/src/commands/cardano_stake_distribution/download.rs +++ b/mithril-client-cli/src/commands/cardano_stake_distribution/download.rs @@ -37,9 +37,9 @@ pub struct CardanoStakeDistributionDownloadCommand { impl CardanoStakeDistributionDownloadCommand { /// Main command execution - pub async fn execute(&self, context: CommandContext) -> MithrilResult<()> { - let params = context.config_parameters()?.add_source(self)?; - let download_dir = params.get_or("download_dir", "."); + pub async fn execute(&self, mut context: CommandContext) -> MithrilResult<()> { + context.config_parameters_mut().add_source(self)?; + let download_dir = context.config_parameters().get_or("download_dir", "."); let download_dir = Path::new(&download_dir); let logger = context.logger(); @@ -49,7 +49,7 @@ impl CardanoStakeDistributionDownloadCommand { ProgressOutputType::Tty }; let progress_printer = ProgressPrinter::new(progress_output_type, 4); - let client = client_builder(¶ms)? + let client = client_builder(context.config_parameters())? .add_feedback_receiver(Arc::new(IndicatifFeedbackReceiver::new( progress_output_type, logger.clone(), diff --git a/mithril-client-cli/src/commands/cardano_stake_distribution/list.rs b/mithril-client-cli/src/commands/cardano_stake_distribution/list.rs index 291842702bd..b3d8908b635 100644 --- a/mithril-client-cli/src/commands/cardano_stake_distribution/list.rs +++ b/mithril-client-cli/src/commands/cardano_stake_distribution/list.rs @@ -11,8 +11,7 @@ pub struct CardanoStakeDistributionListCommand {} impl CardanoStakeDistributionListCommand { /// Main command execution pub async fn execute(&self, context: CommandContext) -> MithrilResult<()> { - let params = context.config_parameters()?; - let client = client_builder_with_fallback_genesis_key(¶ms)? + let client = client_builder_with_fallback_genesis_key(context.config_parameters())? .with_logger(context.logger().clone()) .build()?; let lines = client.cardano_stake_distribution().list().await?; diff --git a/mithril-client-cli/src/commands/cardano_transaction/certify.rs b/mithril-client-cli/src/commands/cardano_transaction/certify.rs index 34431b3f04d..b8532e4311c 100644 --- a/mithril-client-cli/src/commands/cardano_transaction/certify.rs +++ b/mithril-client-cli/src/commands/cardano_transaction/certify.rs @@ -30,8 +30,8 @@ pub struct CardanoTransactionsCertifyCommand { impl CardanoTransactionsCertifyCommand { /// Cardano transaction certify command - pub async fn execute(&self, context: CommandContext) -> MithrilResult<()> { - let params = context.config_parameters()?.add_source(self)?; + pub async fn execute(&self, mut context: CommandContext) -> MithrilResult<()> { + context.config_parameters_mut().add_source(self)?; let logger = context.logger(); let progress_output_type = if context.is_json_output_enabled() { @@ -40,7 +40,7 @@ impl CardanoTransactionsCertifyCommand { ProgressOutputType::Tty }; let progress_printer = ProgressPrinter::new(progress_output_type, 4); - let client = client_builder(¶ms)? + let client = client_builder(context.config_parameters())? .add_feedback_receiver(Arc::new(IndicatifFeedbackReceiver::new( progress_output_type, logger.clone(), diff --git a/mithril-client-cli/src/commands/cardano_transaction/snapshot_list.rs b/mithril-client-cli/src/commands/cardano_transaction/snapshot_list.rs index 00f052e53d8..f2d98e108e3 100644 --- a/mithril-client-cli/src/commands/cardano_transaction/snapshot_list.rs +++ b/mithril-client-cli/src/commands/cardano_transaction/snapshot_list.rs @@ -13,8 +13,7 @@ pub struct CardanoTransactionSnapshotListCommand {} impl CardanoTransactionSnapshotListCommand { /// Main command execution pub async fn execute(&self, context: CommandContext) -> MithrilResult<()> { - let params = context.config_parameters()?; - let client = client_builder_with_fallback_genesis_key(¶ms)? + let client = client_builder_with_fallback_genesis_key(context.config_parameters())? .with_logger(context.logger().clone()) .build()?; let lines = client.cardano_transaction().list_snapshots().await?; diff --git a/mithril-client-cli/src/commands/cardano_transaction/snapshot_show.rs b/mithril-client-cli/src/commands/cardano_transaction/snapshot_show.rs index 470b54b8ad8..672f9ee5109 100644 --- a/mithril-client-cli/src/commands/cardano_transaction/snapshot_show.rs +++ b/mithril-client-cli/src/commands/cardano_transaction/snapshot_show.rs @@ -17,8 +17,7 @@ pub struct CardanoTransactionsSnapshotShowCommand { impl CardanoTransactionsSnapshotShowCommand { /// Cardano transaction snapshot Show command pub async fn execute(&self, context: CommandContext) -> MithrilResult<()> { - let params = context.config_parameters()?; - let client = client_builder_with_fallback_genesis_key(¶ms)? + let client = client_builder_with_fallback_genesis_key(context.config_parameters())? .with_logger(context.logger().clone()) .build()?; diff --git a/mithril-client-cli/src/commands/mithril_stake_distribution/download.rs b/mithril-client-cli/src/commands/mithril_stake_distribution/download.rs index 4a002a6a015..d3c31ea6676 100644 --- a/mithril-client-cli/src/commands/mithril_stake_distribution/download.rs +++ b/mithril-client-cli/src/commands/mithril_stake_distribution/download.rs @@ -37,9 +37,9 @@ pub struct MithrilStakeDistributionDownloadCommand { impl MithrilStakeDistributionDownloadCommand { /// Main command execution - pub async fn execute(&self, context: CommandContext) -> MithrilResult<()> { - let params = context.config_parameters()?.add_source(self)?; - let download_dir = params.get_or("download_dir", "."); + pub async fn execute(&self, mut context: CommandContext) -> MithrilResult<()> { + context.config_parameters_mut().add_source(self)?; + let download_dir = context.config_parameters().get_or("download_dir", "."); let download_dir = Path::new(&download_dir); let logger = context.logger(); @@ -49,7 +49,7 @@ impl MithrilStakeDistributionDownloadCommand { ProgressOutputType::Tty }; let progress_printer = ProgressPrinter::new(progress_output_type, 4); - let client = client_builder(¶ms)? + let client = client_builder(context.config_parameters())? .add_feedback_receiver(Arc::new(IndicatifFeedbackReceiver::new( progress_output_type, logger.clone(), diff --git a/mithril-client-cli/src/commands/mithril_stake_distribution/list.rs b/mithril-client-cli/src/commands/mithril_stake_distribution/list.rs index 74680627c17..3000d1201ee 100644 --- a/mithril-client-cli/src/commands/mithril_stake_distribution/list.rs +++ b/mithril-client-cli/src/commands/mithril_stake_distribution/list.rs @@ -11,8 +11,7 @@ pub struct MithrilStakeDistributionListCommand {} impl MithrilStakeDistributionListCommand { /// Main command execution pub async fn execute(&self, context: CommandContext) -> MithrilResult<()> { - let params = context.config_parameters()?; - let client = client_builder_with_fallback_genesis_key(¶ms)? + let client = client_builder_with_fallback_genesis_key(context.config_parameters())? .with_logger(context.logger().clone()) .build()?; let lines = client.mithril_stake_distribution().list().await?; diff --git a/mithril-client-cli/src/configuration.rs b/mithril-client-cli/src/configuration.rs index adeda48db26..87c2a52f1d0 100644 --- a/mithril-client-cli/src/configuration.rs +++ b/mithril-client-cli/src/configuration.rs @@ -49,11 +49,11 @@ impl ConfigParameters { } /// Fill the holder with parameters from a source - pub fn add_source(mut self, source: &impl ConfigSource) -> Result { + pub fn add_source(&mut self, source: &impl ConfigSource) -> Result<(), ConfigError> { let extra = source.collect()?; self.parameters.extend(extra); - Ok(self) + Ok(()) } /// Fetch a parameter from the holder. @@ -155,9 +155,8 @@ mod tests { #[test] fn test_add_source_to_config() { - let config = ConfigParameters::build(&[("pika", "chu"), ("chari", "zard")]) - .add_source(&TestSource::from([("jiggly", "puff")])) - .unwrap(); + let mut config = ConfigParameters::build(&[("pika", "chu"), ("chari", "zard")]); + config.add_source(&TestSource::from([("jiggly", "puff")])).unwrap(); assert_eq!( ConfigParameters { @@ -173,9 +172,8 @@ mod tests { #[test] fn test_add_source_replace_existing_value() { - let config = ConfigParameters::build(&[("pika", "pika")]) - .add_source(&TestSource::from([("pika", "not chu")])) - .unwrap(); + let mut config = ConfigParameters::build(&[("pika", "pika")]); + config.add_source(&TestSource::from([("pika", "not chu")])).unwrap(); assert_eq!( ConfigParameters { diff --git a/mithril-client-cli/src/lib.rs b/mithril-client-cli/src/lib.rs index 0cab3f6b998..3d09e2d44d0 100644 --- a/mithril-client-cli/src/lib.rs +++ b/mithril-client-cli/src/lib.rs @@ -16,5 +16,6 @@ mod configuration; mod utils; pub use command_context::*; +pub use configuration::*; /// Error Clap pub type ClapError = clap::error::Error; diff --git a/mithril-client-cli/src/main.rs b/mithril-client-cli/src/main.rs index 9a2805a02e6..8e65140dde4 100644 --- a/mithril-client-cli/src/main.rs +++ b/mithril-client-cli/src/main.rs @@ -2,10 +2,11 @@ use anyhow::{Context, anyhow}; use clap::{CommandFactory, Parser, Subcommand}; -use config::{ConfigBuilder, Map, Source, Value, builder::DefaultState}; +use config::{Map, Source, Value}; use mithril_cli_helper::{register_config_value, register_config_value_option}; use slog::{Drain, Fuse, Level, Logger, debug}; use slog_term::Decorator; +use std::collections::HashMap; use std::io::Write; use std::sync::Arc; use std::{fs::File, path::PathBuf}; @@ -19,7 +20,7 @@ use mithril_client_cli::commands::{ cardano_transaction::CardanoTransactionCommands, mithril_stake_distribution::MithrilStakeDistributionCommands, tools::ToolsCommands, }; -use mithril_client_cli::{ClapError, CommandContext}; +use mithril_client_cli::{ClapError, CommandContext, ConfigParameters}; enum LogOutputType { StdErr, @@ -70,6 +71,10 @@ pub struct Args { #[example = "`https://aggregator.pre-release-preview.api.mithril.network/aggregator`"] aggregator_endpoint: Option, + /// Enable JSON output for command results + #[clap(long, global = true)] + json: bool, + /// Enable JSON output for logs displayed according to verbosity level #[clap(long)] log_format_json: bool, @@ -86,9 +91,6 @@ pub struct Args { /// Request origin tag #[clap(long)] origin_tag: Option, - - #[clap(long, global = true)] - json: bool, } impl Args { @@ -99,13 +101,9 @@ impl Args { env!("CARGO_PKG_VERSION") ); debug!(root_logger, "Run Mode: {}", self.run_mode); - let filename = format!("{}/{}.json", self.config_directory.display(), self.run_mode); - debug!(root_logger, "Reading configuration file '{filename}'."); - let config: ConfigBuilder = config::Config::builder() - .add_source(config::File::with_name(&filename).required(false)) - .add_source(self.clone()) - .set_default("download_dir", "")?; - let context = CommandContext::new(config, self.unstable, self.json, root_logger); + + let config_parameters = self.config_parameters(&root_logger)?; + let context = CommandContext::new(config_parameters, self.unstable, self.json, root_logger); self.command.execute(context).await } @@ -174,6 +172,19 @@ impl Args { let styles = Args::command().get_styles().clone(); Deprecation::handle_deprecated_commands(args_result, styles, deprecated_commands) } + + fn config_parameters(&self, root_logger: &Logger) -> MithrilResult { + let filename = format!("{}/{}.json", self.config_directory.display(), self.run_mode); + debug!(root_logger, "Reading configuration file '{filename}'."); + let config = config::Config::builder() + .add_source(config::File::with_name(&filename).required(false)) + .add_source(self.clone()) + .set_default("download_dir", "")? + .build()?; + let config_hash_map = config.try_deserialize::>()?; + + Ok(ConfigParameters::new(config_hash_map)) + } } impl Source for Args { From caff9bfc8581abd577d78e8d59c8b47c4b4cab3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Turmel?= Date: Thu, 3 Jul 2025 17:34:37 +0200 Subject: [PATCH 3/6] feature(client-cli): make all clap root arguments global --- mithril-client-cli/src/main.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mithril-client-cli/src/main.rs b/mithril-client-cli/src/main.rs index 8e65140dde4..5d2773452f6 100644 --- a/mithril-client-cli/src/main.rs +++ b/mithril-client-cli/src/main.rs @@ -54,20 +54,20 @@ pub struct Args { command: ArtifactCommands, /// Run Mode. - #[clap(long, env = "RUN_MODE", default_value = "dev")] + #[clap(long, env = "RUN_MODE", default_value = "dev", global = true)] run_mode: String, /// Verbosity level (-v=warning, -vv=info, -vvv=debug, -vvvv=trace). - #[clap(short, long, action = clap::ArgAction::Count)] + #[clap(short, long, action = clap::ArgAction::Count, global = true)] #[example = "Parsed from the number of occurrences: `-v` for `Warning`, `-vv` for `Info`, `-vvv` for `Debug` and `-vvvv` for `Trace`"] verbose: u8, /// Directory where configuration file is located. - #[clap(long, default_value = "./config")] + #[clap(long, default_value = "./config", global = true)] pub config_directory: PathBuf, /// Override configuration Aggregator endpoint URL. - #[clap(long, env = "AGGREGATOR_ENDPOINT")] + #[clap(long, env = "AGGREGATOR_ENDPOINT", global = true)] #[example = "`https://aggregator.pre-release-preview.api.mithril.network/aggregator`"] aggregator_endpoint: Option, @@ -76,20 +76,20 @@ pub struct Args { json: bool, /// Enable JSON output for logs displayed according to verbosity level - #[clap(long)] + #[clap(long, global = true)] log_format_json: bool, /// Redirect the logs to a file - #[clap(long, alias("o"))] + #[clap(long, alias("o"), global = true)] #[example = "`./mithril-client.log`"] log_output: Option, /// Enable unstable commands - #[clap(long)] + #[clap(long, global = true)] unstable: bool, /// Request origin tag - #[clap(long)] + #[clap(long, global = true)] origin_tag: Option, } From e79b500d343699c8c50ea43c2a40910f766b8ba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Turmel?= Date: Thu, 3 Jul 2025 11:34:06 +0200 Subject: [PATCH 4/6] feature(client-cli): add print of the version at each command execution --- mithril-client-cli/src/main.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/mithril-client-cli/src/main.rs b/mithril-client-cli/src/main.rs index 5d2773452f6..1d7ce5ca77a 100644 --- a/mithril-client-cli/src/main.rs +++ b/mithril-client-cli/src/main.rs @@ -95,11 +95,7 @@ pub struct Args { impl Args { pub async fn execute(&self, root_logger: Logger) -> MithrilResult<()> { - debug!( - root_logger, - "Mithril client CLI version: {}", - env!("CARGO_PKG_VERSION") - ); + self.print_and_log_version(&root_logger); debug!(root_logger, "Run Mode: {}", self.run_mode); let config_parameters = self.config_parameters(&root_logger)?; @@ -108,6 +104,19 @@ impl Args { self.command.execute(context).await } + fn print_and_log_version(&self, root_logger: &Logger) { + let client_cli_version = env!("CARGO_PKG_VERSION"); + let version_message = format!("Mithril Client CLI version: {client_cli_version}"); + if self.json { + let json_message = serde_json::json!({ + "mithril_client_cli_version": client_cli_version}); + eprintln!("{json_message}"); + } else { + eprintln!("{version_message}"); + } + debug!(root_logger, "{version_message}"); + } + fn log_level(&self) -> Level { match self.verbose { 0 => Level::Error, From b48645752cf9e3a61e7681ae7edb07c7ce5164be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Turmel?= Date: Fri, 4 Jul 2025 11:09:41 +0200 Subject: [PATCH 5/6] feature(docs): update client CLI docs with args available in all commands --- .../manual/develop/nodes/mithril-client.md | 201 ++++++++++++++---- .../src/commands/cardano_db/download/mod.rs | 1 + .../src/commands/cardano_db/list.rs | 1 + .../src/commands/cardano_db/show.rs | 1 + .../src/commands/cardano_db/verify.rs | 1 + .../src/commands/tools/snapshot_converter.rs | 6 +- 6 files changed, 164 insertions(+), 47 deletions(-) diff --git a/docs/website/root/manual/develop/nodes/mithril-client.md b/docs/website/root/manual/develop/nodes/mithril-client.md index d7a0efa86cd..9e7a275b205 100644 --- a/docs/website/root/manual/develop/nodes/mithril-client.md +++ b/docs/website/root/manual/develop/nodes/mithril-client.md @@ -234,6 +234,8 @@ Options: Directory where configuration file is located [default: ./config] --aggregator-endpoint Override configuration Aggregator endpoint URL [env: AGGREGATOR_ENDPOINT=] + --json + Enable JSON output for command results --log-format-json Enable JSON output for logs displayed according to verbosity level --log-output @@ -539,6 +541,7 @@ Here is a list of the available parameters: | `unstable` | `--unstable` | - | - | Enable unstable commands | `false` | - | - | | `run_mode` | `--run-mode` | - | `RUN_MODE` | Run Mode | `dev` | - | :heavy_check_mark: | | `aggregator_endpoint` | `--aggregator-endpoint` | - | `AGGREGATOR_ENDPOINT` | Override configuration Aggregator endpoint URL | - | `https://aggregator.pre-release-preview.api.mithril.network/aggregator` | :heavy_check_mark: | +| `json` | `--json` | - | - | Enable JSON output for command results | `false` | - | - | | `log_format_json` | `--log-format-json` | - | - | Enable JSON output for logs displayed according to verbosity level | `false` | - | - | | `log_output` | `--log-output` | - | - | Redirect the logs to a file | - | - | - | | `origin_tag` | `--origin-tag` | - | - | Request origin tag | - | - | - | @@ -546,24 +549,41 @@ Here is a list of the available parameters: `cardano-db snapshot show` command: -| Parameter | Command line (long) | Command line (short) | Environment variable | Description | Default value | Example | Mandatory | -| --------- | ------------------- | :------------------: | -------------------- | --------------------------------------------------------------------------------------------------------------------- | ------------- | ------- | :----------------: | -| `json` | `--json` | - | - | Enable JSON output for command results | `false` | - | - | -| `backend` | `--backend` | `-b` | - | Backend to use, either: `v1` (default, full database restoration only) or `v2` (full or partial database restoration) | `v1` | - | - | -| `digest` | - | - | - | Digest of the Cardano db snapshot to show or `latest` for the latest artifact | - | - | :heavy_check_mark: | +| Parameter | Command line (long) | Command line (short) | Environment variable | Description | Default value | Example | Mandatory | +| --------------------- | ----------------------- | :------------------: | --------------------- | --------------------------------------------------------------------------------------------------------------------- | ------------- | ------- | :----------------: | +| `backend` | `--backend` | `-b` | - | Backend to use, either: `v1` (default, full database restoration only) or `v2` (full or partial database restoration) | `v1` | - | - | +| `digest` | - | - | - | Digest of the Cardano db snapshot to show or `latest` for the latest artifact | - | - | :heavy_check_mark: | +| `run_mode` | `--run-mode` | - | `RUN_MODE` | Run Mode | `dev` | - | - | +| `verbose` | `--verbose` | `-v` | - | Verbosity level (-v=warning, -vv=info, -vvv=debug, -vvvv=trace) | `0` | - | - | +| `config_directory` | `--config-directory` | - | - | Directory where configuration file is located | `./config` | - | - | +| `aggregator_endpoint` | `--aggregator-endpoint` | - | `AGGREGATOR_ENDPOINT` | Override configuration Aggregator endpoint URL | - | - | - | +| `json` | `--json` | - | - | Enable JSON output for command results | `false` | - | - | +| `log_format_json` | `--log-format-json` | - | - | Enable JSON output for logs displayed according to verbosity level | `false` | - | - | +| `log_output` | `--log-output` | - | - | Redirect the logs to a file | - | - | - | +| `unstable` | `--unstable` | - | - | Enable unstable commands | `false` | - | - | +| `origin_tag` | `--origin-tag` | - | - | Request origin tag | - | - | - | +| `help` | `--help` | `-h` | - | Print help (see more with '--help') | - | - | - | `cardano-db snapshot list` command: -| Parameter | Command line (long) | Command line (short) | Environment variable | Description | Default value | Example | Mandatory | -| --------- | ------------------- | :------------------: | -------------------- | --------------------------------------------------------------------------------------------------------------------- | ------------- | ------- | :-------: | -| `json` | `--json` | - | - | Enable JSON output for command results | `false` | - | - | -| `backend` | `--backend` | `-b` | - | Backend to use, either: `v1` (default, full database restoration only) or `v2` (full or partial database restoration) | `v1` | - | - | +| Parameter | Command line (long) | Command line (short) | Environment variable | Description | Default value | Example | Mandatory | +| --------------------- | ----------------------- | :------------------: | --------------------- | --------------------------------------------------------------------------------------------------------------------- | ------------- | ------- | :-------: | +| `backend` | `--backend` | `-b` | - | Backend to use, either: `v1` (default, full database restoration only) or `v2` (full or partial database restoration) | `v1` | - | - | +| `run_mode` | `--run-mode` | - | `RUN_MODE` | Run Mode | `dev` | - | - | +| `verbose` | `--verbose` | `-v` | - | Verbosity level (-v=warning, -vv=info, -vvv=debug, -vvvv=trace) | `0` | - | - | +| `config_directory` | `--config-directory` | - | - | Directory where configuration file is located | `./config` | - | - | +| `aggregator_endpoint` | `--aggregator-endpoint` | - | `AGGREGATOR_ENDPOINT` | Override configuration Aggregator endpoint URL | - | - | - | +| `json` | `--json` | - | - | Enable JSON output for command results | `false` | - | - | +| `log_format_json` | `--log-format-json` | - | - | Enable JSON output for logs displayed according to verbosity level | `false` | - | - | +| `log_output` | `--log-output` | - | - | Redirect the logs to a file | - | - | - | +| `unstable` | `--unstable` | - | - | Enable unstable commands | `false` | - | - | +| `origin_tag` | `--origin-tag` | - | - | Request origin tag | - | - | - | +| `help` | `--help` | `-h` | - | Print help (see more with '--help') | - | - | - | `cardano-db download` command: | Parameter | Command line (long) | Command line (short) | Environment variable | Description | Default value | Example | Mandatory | | ---------------------------- | ------------------------------ | :------------------: | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | ------------- | ------- | :----------------: | -| `json` | `--json` | - | - | Enable JSON output for command results | `false` | - | - | | `backend` | `--backend` | `-b` | - | Backend to use, either: `v1` (default, full database restoration only) or `v2` (full or partial database restoration) | `v1` | - | - | | `digest` | - | - | - | Digest of the Cardano db snapshot to download or `latest` for the latest artifact | - | - | :heavy_check_mark: | | `download_dir` | `--download-dir` | - | - | Directory where the immutable and ancillary files will be downloaded | - | - | - | @@ -573,67 +593,149 @@ Here is a list of the available parameters: | `start` | `--start` | - | - | [backend `v2` only] The first immutable file number to download | - | - | - | | `end` | `--end` | - | - | [backend `v2` only] The last immutable file number to download | - | - | - | | `allow_override` | `--allow-override` | - | - | [backend `v2` only] Allow existing files in the download directory to be overridden | `false` | - | - | +| `run_mode` | `--run-mode` | - | `RUN_MODE` | Run Mode | `dev` | - | - | +| `verbose` | `--verbose` | `-v` | - | Verbosity level (-v=warning, -vv=info, -vvv=debug, -vvvv=trace) | `0` | - | - | +| `config_directory` | `--config-directory` | - | - | Directory where configuration file is located | `./config` | - | - | +| `aggregator_endpoint` | `--aggregator-endpoint` | - | `AGGREGATOR_ENDPOINT` | Override configuration Aggregator endpoint URL | - | - | - | +| `json` | `--json` | - | - | Enable JSON output for command results | `false` | - | - | +| `log_format_json` | `--log-format-json` | - | - | Enable JSON output for logs displayed according to verbosity level | `false` | - | - | +| `log_output` | `--log-output` | - | - | Redirect the logs to a file | - | - | - | +| `unstable` | `--unstable` | - | - | Enable unstable commands | `false` | - | - | +| `origin_tag` | `--origin-tag` | - | - | Request origin tag | - | - | - | +| `help` | `--help` | `-h` | - | Print help (see more with '--help') | - | - | - | `cardano-db verify` command (`v2` backend only): -| Parameter | Command line (long) | Command line (short) | Environment variable | Description | Default value | Example | Mandatory | -| -------------------------- | ---------------------------- | :------------------: | -------------------------- | ------------------------------------------------------------------------------- | ------------- | ------- | :----------------: | -| `backend` | `--backend` | `-b` | - | - | `v2` | - | - | -| `json` | `--json` | - | - | Enable JSON output for command results | `false` | - | - | -| `digest` | - | - | - | Digest of the Cardano db snapshot to verify or `latest` for the latest artifact | - | - | :heavy_check_mark: | -| `db_dir` | `--db-dir` | - | - | Directory from where the immutable will be verified | - | - | - | -| `genesis_verification_key` | `--genesis-verification-key` | - | `GENESIS_VERIFICATION_KEY` | Genesis verification key to check the certificate chain | - | - | - | +| Parameter | Command line (long) | Command line (short) | Environment variable | Description | Default value | Example | Mandatory | +| -------------------------- | ---------------------------- | :------------------: | -------------------------- | --------------------------------------------------------------------------------------------------------------------- | ------------- | ------- | :----------------: | +| `backend` | `--backend` | `-b` | - | Backend to use, either: `v1` (default, full database restoration only) or `v2` (full or partial database restoration) | `v2` | - | - | +| `digest` | - | - | - | Digest of the Cardano db snapshot to verify or `latest` for the latest artifact | - | - | :heavy_check_mark: | +| `db_dir` | `--db-dir` | - | - | Directory from where the immutable will be verified | - | - | - | +| `genesis_verification_key` | `--genesis-verification-key` | - | `GENESIS_VERIFICATION_KEY` | Genesis verification key to check the certificate chain | - | - | - | +| `run_mode` | `--run-mode` | - | `RUN_MODE` | Run Mode | `dev` | - | - | +| `verbose` | `--verbose` | `-v` | - | Verbosity level (-v=warning, -vv=info, -vvv=debug, -vvvv=trace) | `0` | - | - | +| `config_directory` | `--config-directory` | - | - | Directory where configuration file is located | `./config` | - | - | +| `aggregator_endpoint` | `--aggregator-endpoint` | - | `AGGREGATOR_ENDPOINT` | Override configuration Aggregator endpoint URL | - | - | - | +| `json` | `--json` | - | - | Enable JSON output for command results | `false` | - | - | +| `log_format_json` | `--log-format-json` | - | - | Enable JSON output for logs displayed according to verbosity level | `false` | - | - | +| `log_output` | `--log-output` | - | - | Redirect the logs to a file | - | - | - | +| `unstable` | `--unstable` | - | - | Enable unstable commands | `false` | - | - | +| `origin_tag` | `--origin-tag` | - | - | Request origin tag | - | - | - | +| `help` | `--help` | `-h` | - | Print help (see more with '--help') | - | - | - | `mithril-stake-distribution list` command: -| Parameter | Command line (long) | Command line (short) | Environment variable | Description | Default value | Example | Mandatory | -| --------- | ------------------- | :------------------: | -------------------- | -------------------------------------- | ------------- | ------- | :-------: | -| `json` | `--json` | - | - | Enable JSON output for command results | `false` | - | - | +| Parameter | Command line (long) | Command line (short) | Environment variable | Description | Default value | Example | Mandatory | +| --------------------- | ----------------------- | :------------------: | --------------------- | ------------------------------------------------------------------ | ------------- | ------- | :-------: | +| `run_mode` | `--run-mode` | - | `RUN_MODE` | Run Mode | `dev` | - | - | +| `verbose` | `--verbose` | `-v` | - | Verbosity level (-v=warning, -vv=info, -vvv=debug, -vvvv=trace) | `0` | - | - | +| `config_directory` | `--config-directory` | - | - | Directory where configuration file is located | `./config` | - | - | +| `aggregator_endpoint` | `--aggregator-endpoint` | - | `AGGREGATOR_ENDPOINT` | Override configuration Aggregator endpoint URL | - | - | - | +| `json` | `--json` | - | - | Enable JSON output for command results | `false` | - | - | +| `log_format_json` | `--log-format-json` | - | - | Enable JSON output for logs displayed according to verbosity level | `false` | - | - | +| `log_output` | `--log-output` | - | - | Redirect the logs to a file | - | - | - | +| `unstable` | `--unstable` | - | - | Enable unstable commands | `false` | - | - | +| `origin_tag` | `--origin-tag` | - | - | Request origin tag | - | - | - | +| `help` | `--help` | `-h` | - | Print help | - | - | - | `mithril-stake-distribution download` command: | Parameter | Command line (long) | Command line (short) | Environment variable | Description | Default value | Example | Mandatory | | -------------------------- | ---------------------------- | :------------------: | -------------------------- | ------------------------------------------------------------------------------------ | ------------- | ------- | :----------------: | -| `json` | `--json` | - | - | Enable JSON output for command results | `false` | - | - | | `artifact_hash` | - | - | - | Hash of the Mithril stake distribution artifact, or `latest` for the latest artifact | - | - | :heavy_check_mark: | | `download_dir` | `--download-dir` | - | - | Directory where the Mithril stake distribution will be downloaded | - | - | - | | `genesis_verification_key` | `--genesis-verification-key` | - | `GENESIS_VERIFICATION_KEY` | Genesis verification key to check the certificate chain | - | - | :heavy_check_mark: | +| `run_mode` | `--run-mode` | - | `RUN_MODE` | Run Mode | `dev` | - | - | +| `verbose` | `--verbose` | `-v` | - | Verbosity level (-v=warning, -vv=info, -vvv=debug, -vvvv=trace) | `0` | - | - | +| `config_directory` | `--config-directory` | - | - | Directory where configuration file is located | `./config` | - | - | +| `aggregator_endpoint` | `--aggregator-endpoint` | - | `AGGREGATOR_ENDPOINT` | Override configuration Aggregator endpoint URL | - | - | - | +| `json` | `--json` | - | - | Enable JSON output for command results | `false` | - | - | +| `log_format_json` | `--log-format-json` | - | - | Enable JSON output for logs displayed according to verbosity level | `false` | - | - | +| `log_output` | `--log-output` | - | - | Redirect the logs to a file | - | - | - | +| `unstable` | `--unstable` | - | - | Enable unstable commands | `false` | - | - | +| `origin_tag` | `--origin-tag` | - | - | Request origin tag | - | - | - | +| `help` | `--help` | `-h` | - | Print help (see more with '--help') | - | - | - | `cardano-transaction snapshot show` command: -| Parameter | Command line (long) | Command line (short) | Environment variable | Description | Default value | Example | Mandatory | -| --------- | ------------------- | :------------------: | -------------------- | ------------------------------------------------------------------------------------ | ------------- | ------- | :----------------: | -| `json` | `--json` | - | - | Enable JSON output for command results | `false` | - | - | -| `hash` | - | - | - | Hash of the Cardano transaction snapshot to show or `latest` for the latest artifact | - | - | :heavy_check_mark: | +| Parameter | Command line (long) | Command line (short) | Environment variable | Description | Default value | Example | Mandatory | +| --------------------- | ----------------------- | :------------------: | --------------------- | ------------------------------------------------------------------------------------ | ------------- | ------- | :----------------: | +| `hash` | - | - | - | Hash of the Cardano transaction snapshot to show or `latest` for the latest artifact | - | - | :heavy_check_mark: | +| `run_mode` | `--run-mode` | - | `RUN_MODE` | Run Mode | `dev` | - | - | +| `verbose` | `--verbose` | `-v` | - | Verbosity level (-v=warning, -vv=info, -vvv=debug, -vvvv=trace) | `0` | - | - | +| `config_directory` | `--config-directory` | - | - | Directory where configuration file is located | `./config` | - | - | +| `aggregator_endpoint` | `--aggregator-endpoint` | - | `AGGREGATOR_ENDPOINT` | Override configuration Aggregator endpoint URL | - | - | - | +| `json` | `--json` | - | - | Enable JSON output for command results | `false` | - | - | +| `log_format_json` | `--log-format-json` | - | - | Enable JSON output for logs displayed according to verbosity level | `false` | - | - | +| `log_output` | `--log-output` | - | - | Redirect the logs to a file | - | - | - | +| `unstable` | `--unstable` | - | - | Enable unstable commands | `false` | - | - | +| `origin_tag` | `--origin-tag` | - | - | Request origin tag | - | - | - | +| `help` | `--help` | `-h` | - | Print help | - | - | - | `cardano-transaction snapshot list` command: -| Parameter | Command line (long) | Command line (short) | Environment variable | Description | Default value | Example | Mandatory | -| --------- | ------------------- | :------------------: | -------------------- | -------------------------------------- | ------------- | ------- | :-------: | -| `json` | `--json` | - | - | Enable JSON output for command results | `false` | - | - | +| Parameter | Command line (long) | Command line (short) | Environment variable | Description | Default value | Example | Mandatory | +| --------------------- | ----------------------- | :------------------: | --------------------- | ------------------------------------------------------------------ | ------------- | ------- | :-------: | +| `run_mode` | `--run-mode` | - | `RUN_MODE` | Run Mode | `dev` | - | - | +| `verbose` | `--verbose` | `-v` | - | Verbosity level (-v=warning, -vv=info, -vvv=debug, -vvvv=trace) | `0` | - | - | +| `config_directory` | `--config-directory` | - | - | Directory where configuration file is located | `./config` | - | - | +| `aggregator_endpoint` | `--aggregator-endpoint` | - | `AGGREGATOR_ENDPOINT` | Override configuration Aggregator endpoint URL | - | - | - | +| `json` | `--json` | - | - | Enable JSON output for command results | `false` | - | - | +| `log_format_json` | `--log-format-json` | - | - | Enable JSON output for logs displayed according to verbosity level | `false` | - | - | +| `log_output` | `--log-output` | - | - | Redirect the logs to a file | - | - | - | +| `unstable` | `--unstable` | - | - | Enable unstable commands | `false` | - | - | +| `origin_tag` | `--origin-tag` | - | - | Request origin tag | - | - | - | +| `help` | `--help` | `-h` | - | Print help | - | - | - | `cardano-transaction certify` command: -| Parameter | Command line (long) | Command line (short) | Environment variable | Description | Default value | Example | Mandatory | -| -------------------------- | ---------------------------- | :------------------: | -------------------------- | ------------------------------------------------------- | ------------- | ------- | :----------------: | -| `json` | `--json` | - | - | Enable JSON output for command results | `false` | - | - | -| `genesis_verification_key` | `--genesis-verification-key` | - | `GENESIS_VERIFICATION_KEY` | Genesis verification key to check the certificate chain | - | - | :heavy_check_mark: | -| `transactions_hashes` | - | - | - | Hashes of the transactions to certify | - | - | :heavy_check_mark: | +| Parameter | Command line (long) | Command line (short) | Environment variable | Description | Default value | Example | Mandatory | +| -------------------------- | ---------------------------- | :------------------: | -------------------------- | ------------------------------------------------------------------ | ------------- | ------- | :----------------: | +| `genesis_verification_key` | `--genesis-verification-key` | - | `GENESIS_VERIFICATION_KEY` | Genesis verification key to check the certificate chain | - | - | :heavy_check_mark: | +| `transactions_hashes` | - | - | - | Hashes of the transactions to certify | - | - | :heavy_check_mark: | +| `run_mode` | `--run-mode` | - | `RUN_MODE` | Run Mode | `dev` | - | - | +| `verbose` | `--verbose` | `-v` | - | Verbosity level (-v=warning, -vv=info, -vvv=debug, -vvvv=trace) | `0` | - | - | +| `config_directory` | `--config-directory` | - | - | Directory where configuration file is located | `./config` | - | - | +| `aggregator_endpoint` | `--aggregator-endpoint` | - | `AGGREGATOR_ENDPOINT` | Override configuration Aggregator endpoint URL | - | - | - | +| `json` | `--json` | - | - | Enable JSON output for command results | `false` | - | - | +| `log_format_json` | `--log-format-json` | - | - | Enable JSON output for logs displayed according to verbosity level | `false` | - | - | +| `log_output` | `--log-output` | - | - | Redirect the logs to a file | - | - | - | +| `unstable` | `--unstable` | - | - | Enable unstable commands | `false` | - | - | +| `origin_tag` | `--origin-tag` | - | - | Request origin tag | - | - | - | +| `help` | `--help` | `-h` | - | Print help | - | - | - | `cardano-stake-distribution list` command: -| Parameter | Command line (long) | Command line (short) | Environment variable | Description | Default value | Example | Mandatory | -| --------- | ------------------- | :------------------: | -------------------- | -------------------------------------- | ------------- | ------- | :-------: | -| `json` | `--json` | - | - | Enable JSON output for command results | `false` | - | - | +| Parameter | Command line (long) | Command line (short) | Environment variable | Description | Default value | Example | Mandatory | +| --------------------- | ----------------------- | :------------------: | --------------------- | ------------------------------------------------------------------ | ------------- | ------- | :-------: | +| `run_mode` | `--run-mode` | - | `RUN_MODE` | Run Mode | `dev` | - | - | +| `verbose` | `--verbose` | `-v` | - | Verbosity level (-v=warning, -vv=info, -vvv=debug, -vvvv=trace) | `0` | - | - | +| `config_directory` | `--config-directory` | - | - | Directory where configuration file is located | `./config` | - | - | +| `aggregator_endpoint` | `--aggregator-endpoint` | - | `AGGREGATOR_ENDPOINT` | Override configuration Aggregator endpoint URL | - | - | - | +| `json` | `--json` | - | - | Enable JSON output for command results | `false` | - | - | +| `log_format_json` | `--log-format-json` | - | - | Enable JSON output for logs displayed according to verbosity level | `false` | - | - | +| `log_output` | `--log-output` | - | - | Redirect the logs to a file | - | - | - | +| `unstable` | `--unstable` | - | - | Enable unstable commands | `false` | - | - | +| `origin_tag` | `--origin-tag` | - | - | Request origin tag | - | - | - | +| `help` | `--help` | `-h` | - | Print help | - | - | - | `cardano-stake-distribution download` command: | Parameter | Command line (long) | Command line (short) | Environment variable | Description | Default value | Example | Mandatory | | -------------------------- | ---------------------------- | :------------------: | -------------------------- | --------------------------------------------------------------------------------------------- | ------------- | ------- | :----------------: | -| `json` | `--json` | - | - | Enable JSON output for command results | `false` | - | - | | `unique_identifier` | - | - | - | Hash or Epoch of the Cardano stake distribution artifact, or `latest` for the latest artifact | - | - | :heavy_check_mark: | | `download_dir` | `--download-dir` | - | - | Directory where the Cardano stake distribution will be downloaded | - | - | - | | `genesis_verification_key` | `--genesis-verification-key` | - | `GENESIS_VERIFICATION_KEY` | Genesis verification key to check the certificate chain | - | - | :heavy_check_mark: | +| `run_mode` | `--run-mode` | - | `RUN_MODE` | Run Mode | `dev` | - | - | +| `verbose` | `--verbose` | `-v` | - | Verbosity level (-v=warning, -vv=info, -vvv=debug, -vvvv=trace) | `0` | - | - | +| `config_directory` | `--config-directory` | - | - | Directory where configuration file is located | `./config` | - | - | +| `aggregator_endpoint` | `--aggregator-endpoint` | - | `AGGREGATOR_ENDPOINT` | Override configuration Aggregator endpoint URL | - | - | - | +| `json` | `--json` | - | - | Enable JSON output for command results | `false` | - | - | +| `log_format_json` | `--log-format-json` | - | - | Enable JSON output for logs displayed according to verbosity level | `false` | - | - | +| `log_output` | `--log-output` | - | - | Redirect the logs to a file | - | - | - | +| `unstable` | `--unstable` | - | - | Enable unstable commands | `false` | - | - | +| `origin_tag` | `--origin-tag` | - | - | Request origin tag | - | - | - | +| `help` | `--help` | `-h` | - | Print help (see more with '--help') | - | - | - | `tools utxo-hd snapshot-converter` command: @@ -643,10 +745,21 @@ This command is not compatible with **Linux ARM environments**. ::: -| Parameter | Command line (long) | Command line (short) | Environment variable | Description | Default value | Example | Mandatory | -| ---------------------- | ------------------------ | :------------------: | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- | -------- | :----------------: | -| `db_directory` | `--db-directory` | - | - | Path to the Cardano node database directory | - | - | :heavy_check_mark: | -| `cardano_node_version` | `--cardano-node-version` | - | - | Cardano node version of the Mithril signed snapshot (`latest` and `pre-release` are also supported to download the latest or pre-release distribution.) | - | `10.4.1` | :heavy_check_mark: | -| `utxo_hd_flavor` | `--utxo-hd-flavor` | - | - | UTxO-HD flavor to convert the ledger snapshot to (`Legacy` or `LMDB`) | - | `LMDB` | :heavy_check_mark: | -| `commit` | `--commit` | - | - | Replaces the current ledger state in the `db_directory` | `false` | - | - | -| `github_token` | `--github-token` | - | `GITHUB_TOKEN` | GitHub token for authenticated API calls | - | - | - | +| Parameter | Command line (long) | Command line (short) | Environment variable | Description | Default value | Example | Mandatory | +| ---------------------- | ------------------------ | :------------------: | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- | ------- | :----------------: | +| `db_directory` | `--db-directory` | - | - | Path to the Cardano node database directory | - | - | :heavy_check_mark: | +| `cardano_node_version` | `--cardano-node-version` | - | - | Cardano node version of the Mithril signed snapshot (`latest` and `pre-release` are also supported to download the latest or pre-release distribution). | - | - | :heavy_check_mark: | +| `cardano_network` | `--cardano-network` | - | - | Cardano network | - | - | - | +| `utxo_hd_flavor` | `--utxo-hd-flavor` | - | - | UTxO-HD flavor to convert the ledger snapshot to (`Legacy` or `LMDB`) | - | - | :heavy_check_mark: | +| `commit` | `--commit` | - | - | Replaces the current ledger state in the `db_directory`. | `false` | - | - | +| `github_token` | `--github-token` | - | `GITHUB_TOKEN` | GitHub token for authenticated API calls | - | - | - | +| `run_mode` | `--run-mode` | - | `RUN_MODE` | Run Mode | `dev` | - | - | +| `verbose` | `--verbose` | `-v` | - | Verbosity level (-v=warning, -vv=info, -vvv=debug, -vvvv=trace) | `0` | - | - | +| `config_directory` | `--config-directory` | - | - | Directory where configuration file is located | `./config` | - | - | +| `aggregator_endpoint` | `--aggregator-endpoint` | - | `AGGREGATOR_ENDPOINT` | Override configuration Aggregator endpoint URL | - | - | - | +| `json` | `--json` | - | - | Enable JSON output for command results | `false` | - | - | +| `log_format_json` | `--log-format-json` | - | - | Enable JSON output for logs displayed according to verbosity level | `false` | - | - | +| `log_output` | `--log-output` | - | - | Redirect the logs to a file | - | - | - | +| `unstable` | `--unstable` | - | - | Enable unstable commands | `false` | - | - | +| `origin_tag` | `--origin-tag` | - | - | Request origin tag | - | - | - | +| `help` | `--help` | `-h` | - | Print help (see more with '--help') | - | - | - | diff --git a/mithril-client-cli/src/commands/cardano_db/download/mod.rs b/mithril-client-cli/src/commands/cardano_db/download/mod.rs index a78fa1ee65f..30f62e3bad3 100644 --- a/mithril-client-cli/src/commands/cardano_db/download/mod.rs +++ b/mithril-client-cli/src/commands/cardano_db/download/mod.rs @@ -20,6 +20,7 @@ const DB_DIRECTORY_NAME: &str = "db"; /// Clap command to download a Cardano db and verify its associated certificate. #[derive(Parser, Debug, Clone)] pub struct CardanoDbDownloadCommand { + ///Backend to use, either: `v1` (default, full database restoration only) or `v2` (full or partial database restoration) #[arg(short, long, value_enum, default_value_t)] backend: CardanoDbCommandsBackend, diff --git a/mithril-client-cli/src/commands/cardano_db/list.rs b/mithril-client-cli/src/commands/cardano_db/list.rs index 1ab9b3adc9c..1faa4e96568 100644 --- a/mithril-client-cli/src/commands/cardano_db/list.rs +++ b/mithril-client-cli/src/commands/cardano_db/list.rs @@ -11,6 +11,7 @@ use mithril_client::{Client, MithrilResult}; /// Clap command to list existing Cardano dbs #[derive(Parser, Debug, Clone)] pub struct CardanoDbListCommand { + ///Backend to use, either: `v1` (default, full database restoration only) or `v2` (full or partial database restoration) #[arg(short, long, value_enum, default_value_t)] backend: CardanoDbCommandsBackend, } diff --git a/mithril-client-cli/src/commands/cardano_db/show.rs b/mithril-client-cli/src/commands/cardano_db/show.rs index 63808db50b0..c35c4dcacb6 100644 --- a/mithril-client-cli/src/commands/cardano_db/show.rs +++ b/mithril-client-cli/src/commands/cardano_db/show.rs @@ -16,6 +16,7 @@ use crate::{ /// Clap command to show a given Cardano db #[derive(Parser, Debug, Clone)] pub struct CardanoDbShowCommand { + ///Backend to use, either: `v1` (default, full database restoration only) or `v2` (full or partial database restoration) #[arg(short, long, value_enum, default_value_t)] backend: CardanoDbCommandsBackend, diff --git a/mithril-client-cli/src/commands/cardano_db/verify.rs b/mithril-client-cli/src/commands/cardano_db/verify.rs index 6ecb5e85fb5..6545f693423 100644 --- a/mithril-client-cli/src/commands/cardano_db/verify.rs +++ b/mithril-client-cli/src/commands/cardano_db/verify.rs @@ -22,6 +22,7 @@ use crate::{ /// Clap command to verify a Cardano db and its associated certificate. #[derive(Parser, Debug, Clone)] pub struct CardanoDbVerifyCommand { + ///Backend to use, either: `v1` (default, full database restoration only) or `v2` (full or partial database restoration) #[arg(short, long, value_enum, default_value_t = CardanoDbCommandsBackend::V2)] backend: CardanoDbCommandsBackend, diff --git a/mithril-client-cli/src/commands/tools/snapshot_converter.rs b/mithril-client-cli/src/commands/tools/snapshot_converter.rs index 8dd14e2d3c4..48a1e556dde 100644 --- a/mithril-client-cli/src/commands/tools/snapshot_converter.rs +++ b/mithril-client-cli/src/commands/tools/snapshot_converter.rs @@ -121,7 +121,7 @@ pub struct SnapshotConverterCommand { #[clap(long)] db_directory: PathBuf, - /// Cardano node version of the Mithril signed snapshot. + /// Cardano node version of the Mithril signed snapshot (`latest` and `pre-release` are also supported to download the latest or pre-release distribution). /// /// `latest` and `pre-release` are also supported to download the latest or pre-release distribution. #[clap(long)] @@ -135,11 +135,11 @@ pub struct SnapshotConverterCommand { )] cardano_network: Option, - /// UTxO-HD flavor to convert the ledger snapshot to. + /// UTxO-HD flavor to convert the ledger snapshot to (`Legacy` or `LMDB`). #[clap(long)] utxo_hd_flavor: UTxOHDFlavor, - /// If set, the converted snapshot replaces the current ledger state in the `db_directory`. + /// Replaces the current ledger state in the `db_directory`. #[clap(long)] commit: bool, From 0bbd89178424880bc28c03d7e74e3ab5ce000377 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Turmel?= Date: Fri, 4 Jul 2025 14:25:39 +0200 Subject: [PATCH 6/6] chore: upgrade crate versions * mithril-client-cli from `0.12.19` to `0.12.20` --- Cargo.lock | 2 +- mithril-client-cli/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 211f61b5e4a..e498bdc5618 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4108,7 +4108,7 @@ dependencies = [ [[package]] name = "mithril-client-cli" -version = "0.12.19" +version = "0.12.20" dependencies = [ "anyhow", "async-trait", diff --git a/mithril-client-cli/Cargo.toml b/mithril-client-cli/Cargo.toml index 1a2f95c0376..40fce68656f 100644 --- a/mithril-client-cli/Cargo.toml +++ b/mithril-client-cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-client-cli" -version = "0.12.19" +version = "0.12.20" description = "A Mithril Client" authors = { workspace = true } edition = { workspace = true }