Skip to content

Commit 87662dd

Browse files
committed
feat(client-cli): add --epoch parameter to cardano db v2 list command
1 parent 786c9e7 commit 87662dd

File tree

1 file changed

+26
-3
lines changed
  • mithril-client-cli/src/commands/cardano_db

1 file changed

+26
-3
lines changed

mithril-client-cli/src/commands/cardano_db/list.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
use clap::Parser;
22
use cli_table::{Cell, Table, format::Justify, print_stdout};
33

4+
use mithril_client::common::{Epoch, EpochSpecifier};
5+
use mithril_client::{Client, MithrilResult};
6+
47
use crate::{
58
CommandContext,
6-
commands::{cardano_db::CardanoDbCommandsBackend, client_builder_with_fallback_genesis_key},
9+
commands::{
10+
cardano_db::{CardanoDbCommandsBackend, warn_unused_parameter_with_v1_backend},
11+
client_builder_with_fallback_genesis_key,
12+
},
713
utils::CardanoDbUtils,
814
};
9-
use mithril_client::{Client, MithrilResult};
1015

1116
/// Clap command to list existing Cardano dbs
1217
#[derive(Parser, Debug, Clone)]
1318
pub struct CardanoDbListCommand {
1419
///Backend to use, either: `v1` (default, full database restoration only) or `v2` (full or partial database restoration)
1520
#[arg(short, long, value_enum, default_value_t)]
1621
backend: CardanoDbCommandsBackend,
22+
23+
/// [backend `v2` only] Epoch of the Cardano db snapshots to list, or `latest` for the latest artifact, or `latest-X` for the artifact of the latest epoch minus X.
24+
#[clap(long)]
25+
epoch: Option<String>,
1726
}
1827

1928
impl CardanoDbListCommand {
@@ -32,6 +41,10 @@ impl CardanoDbListCommand {
3241
}
3342

3443
async fn print_v1(&self, client: Client, context: CommandContext) -> MithrilResult<()> {
44+
if self.epoch.is_some() {
45+
warn_unused_parameter_with_v1_backend(&context, ["--epoch"]);
46+
}
47+
3548
let items = client.cardano_database().list().await?;
3649

3750
if context.is_json_output_enabled() {
@@ -67,7 +80,17 @@ impl CardanoDbListCommand {
6780
}
6881

6982
async fn print_v2(&self, client: Client, context: CommandContext) -> MithrilResult<()> {
70-
let items = client.cardano_database_v2().list().await?;
83+
let cdb_v2_client = client.cardano_database_v2();
84+
let items = match &self.epoch {
85+
None => cdb_v2_client.list().await?,
86+
Some(epoch_str) => match Epoch::parse_specifier(epoch_str)? {
87+
EpochSpecifier::Number(epoch) => cdb_v2_client.list_by_epoch(epoch).await?,
88+
EpochSpecifier::Latest => cdb_v2_client.list_for_latest_epoch().await?,
89+
EpochSpecifier::LatestMinusOffset(offset) => {
90+
cdb_v2_client.list_for_latest_epoch_with_offset(offset).await?
91+
}
92+
},
93+
};
7194

7295
if context.is_json_output_enabled() {
7396
println!("{}", serde_json::to_string(&items)?);

0 commit comments

Comments
 (0)