mithril_client_cli/commands/cardano_db/
mod.rs1mod download;
3mod list;
4mod shared_steps;
5mod show;
6mod verify;
7
8pub use download::*;
9pub use list::*;
10pub use show::*;
11pub use verify::*;
12
13use clap::{Subcommand, ValueEnum};
14
15use mithril_client::MithrilResult;
16
17use crate::{CommandContext, utils::print_simple_warning};
18
19#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Default, ValueEnum)]
21pub enum CardanoDbCommandsBackend {
22 #[clap(help = "(deprecated) Legacy backend, full database restoration only")]
24 V1,
25 #[default]
27 #[clap(help = "[default] V2 backend, full or partial database restoration")]
28 V2,
29}
30
31#[derive(Subcommand, Debug, Clone)]
33pub enum CardanoDbCommands {
34 #[clap(subcommand)]
36 Snapshot(CardanoDbSnapshotCommands),
37
38 #[clap(arg_required_else_help = true)]
40 Download(CardanoDbDownloadCommand),
41
42 #[clap(arg_required_else_help = true)]
44 Verify(CardanoDbVerifyCommand),
45}
46
47#[derive(Subcommand, Debug, Clone)]
49pub enum CardanoDbSnapshotCommands {
50 #[clap(arg_required_else_help = false)]
52 List(CardanoDbListCommand),
53
54 #[clap(arg_required_else_help = true)]
56 Show(CardanoDbShowCommand),
57}
58
59impl CardanoDbCommands {
60 pub async fn execute(&self, context: CommandContext) -> MithrilResult<()> {
62 match self {
63 Self::Download(cmd) => cmd.execute(context).await,
64 Self::Snapshot(cmd) => cmd.execute(context).await,
65 Self::Verify(cmd) => cmd.execute(context).await,
66 }
67 }
68}
69
70impl CardanoDbSnapshotCommands {
71 pub async fn execute(&self, config_builder: CommandContext) -> MithrilResult<()> {
73 match self {
74 Self::List(cmd) => cmd.execute(config_builder).await,
75 Self::Show(cmd) => cmd.execute(config_builder).await,
76 }
77 }
78}
79
80pub fn warn_deprecated_v1_backend(context: &CommandContext) {
82 let message = "The `v1` backend is deprecated and is scheduled to be removed early 2026. \
83 Please use the `v2` backend instead. \
84 No other change is required in your command line.";
85
86 print_simple_warning(message, context.is_json_output_enabled());
87}
88
89pub fn warn_unused_parameter_with_v1_backend<const N: usize>(
91 context: &CommandContext,
92 v2_only_parameters: [&str; N],
93) {
94 let message = format_unused_parameter_with_v1_backend(v2_only_parameters);
95 print_simple_warning(&message, context.is_json_output_enabled());
96
97 if !context.is_json_output_enabled() {
98 eprintln!();
100 }
101}
102
103fn format_unused_parameter_with_v1_backend<const N: usize>(
104 v2_only_parameters: [&str; N],
105) -> String {
106 match v2_only_parameters.len() {
107 0 => String::new(),
108 1 => format!(
109 "`{}` is only available with the `v2` backend. It will be ignored.",
110 v2_only_parameters[0]
111 ),
112 n => {
113 format!(
114 "`{}`, and `{}` are only available with the `v2` backend. They will be ignored.",
115 v2_only_parameters[..n - 1].join("`, `"),
116 v2_only_parameters[n - 1]
117 )
118 }
119 }
120}
121
122#[cfg(test)]
123mod tests {
124 use super::*;
125
126 #[test]
127 fn test_format_unused_parameter_with_v1_backend() {
128 assert_eq!(format_unused_parameter_with_v1_backend([]), String::new());
129
130 assert_eq!(
131 format_unused_parameter_with_v1_backend(["--test"]),
132 "`--test` is only available with the `v2` backend. It will be ignored.".to_string()
133 );
134
135 assert_eq!(
136 format_unused_parameter_with_v1_backend(["--foo", "--bar"]),
137 "`--foo`, and `--bar` are only available with the `v2` backend. They will be ignored."
138 .to_string()
139 );
140
141 assert_eq!(
142 format_unused_parameter_with_v1_backend(["--test", "--foo", "--bar"]),
143 "`--test`, `--foo`, and `--bar` are only available with the `v2` backend. They will be ignored.".to_string()
144 );
145 }
146}