-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2266 from input-output-hk/dlachaume/2246/implemen…
…t-incremental-cardano-db-client-cli Feat: Implement `cardano-db-v2` command in client CLI (`list` and `show`)
- Loading branch information
Showing
19 changed files
with
595 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use clap::Parser; | ||
use cli_table::{format::Justify, print_stdout, Cell, Table}; | ||
|
||
use mithril_client::MithrilResult; | ||
|
||
use crate::{ | ||
commands::{client_builder_with_fallback_genesis_key, SharedArgs}, | ||
utils::CardanoDbUtils, | ||
CommandContext, | ||
}; | ||
|
||
/// Clap command to list existing cardano db snapshots | ||
#[derive(Parser, Debug, Clone)] | ||
pub struct CardanoDbListCommand { | ||
#[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()?; | ||
let client = client_builder_with_fallback_genesis_key(¶ms)? | ||
.with_logger(context.logger().clone()) | ||
.build()?; | ||
let items = client.cardano_database().list().await?; | ||
|
||
if self.is_json_output_enabled() { | ||
println!("{}", serde_json::to_string(&items)?); | ||
} else { | ||
let items = items | ||
.into_iter() | ||
.map(|item| { | ||
vec![ | ||
format!("{}", item.beacon.epoch).cell(), | ||
format!("{}", item.beacon.immutable_file_number).cell(), | ||
item.hash.cell(), | ||
item.merkle_root.cell(), | ||
CardanoDbUtils::format_bytes_to_gigabytes(item.total_db_size_uncompressed) | ||
.cell(), | ||
format!("{}", item.compression_algorithm).cell(), | ||
item.cardano_node_version.cell(), | ||
item.created_at.to_string().cell(), | ||
] | ||
}) | ||
.collect::<Vec<_>>() | ||
.table() | ||
.title(vec![ | ||
"Epoch".cell(), | ||
"Immutable".cell(), | ||
"Hash".cell(), | ||
"Merkle root".cell(), | ||
"Database size".cell().justify(Justify::Right), | ||
"Compression".cell(), | ||
"Cardano node".cell(), | ||
"Created".cell().justify(Justify::Right), | ||
]); | ||
print_stdout(items)?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//! Commands for the cardano db v2 artifact | ||
mod list; | ||
mod show; | ||
|
||
pub use list::*; | ||
pub use show::*; | ||
|
||
use crate::CommandContext; | ||
use clap::Subcommand; | ||
use mithril_client::MithrilResult; | ||
|
||
/// Cardano db v2 management (alias: cdbv2) | ||
#[derive(Subcommand, Debug, Clone)] | ||
pub enum CardanoDbV2Commands { | ||
/// Cardano db snapshot v2 commands | ||
#[clap(subcommand)] | ||
Snapshot(CardanoDbV2SnapshotCommands), | ||
} | ||
|
||
/// Cardano db v2 snapshots | ||
#[derive(Subcommand, Debug, Clone)] | ||
pub enum CardanoDbV2SnapshotCommands { | ||
/// List available cardano db v2 snapshots | ||
#[clap(arg_required_else_help = false)] | ||
List(CardanoDbListCommand), | ||
|
||
/// Show detailed information about a cardano db v2 snapshot | ||
#[clap(arg_required_else_help = true)] | ||
Show(CardanoDbShowCommand), | ||
} | ||
|
||
impl CardanoDbV2Commands { | ||
/// Execute Cardano db v2 command | ||
pub async fn execute(&self, config_builder: CommandContext) -> MithrilResult<()> { | ||
match self { | ||
Self::Snapshot(cmd) => cmd.execute(config_builder).await, | ||
} | ||
} | ||
} | ||
|
||
impl CardanoDbV2SnapshotCommands { | ||
/// Execute Cardano db v2 snapshot command | ||
pub async fn execute(&self, config_builder: CommandContext) -> MithrilResult<()> { | ||
match self { | ||
Self::List(cmd) => cmd.execute(config_builder).await, | ||
Self::Show(cmd) => cmd.execute(config_builder).await, | ||
} | ||
} | ||
} |
Oops, something went wrong.