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 crate::CommandContext;
14use clap::{Subcommand, ValueEnum};
15use mithril_client::MithrilResult;
16
17#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Default, ValueEnum)]
19pub enum CardanoDbCommandsBackend {
20 #[clap(help = "(deprecated) Legacy backend, full database restoration only")]
22 V1,
23 #[default]
25 #[clap(help = "[default] V2 backend, full or partial database restoration")]
26 V2,
27}
28
29#[derive(Subcommand, Debug, Clone)]
31pub enum CardanoDbCommands {
32 #[clap(subcommand)]
34 Snapshot(CardanoDbSnapshotCommands),
35
36 #[clap(arg_required_else_help = true)]
38 Download(CardanoDbDownloadCommand),
39
40 #[clap(arg_required_else_help = true)]
42 Verify(CardanoDbVerifyCommand),
43}
44
45#[derive(Subcommand, Debug, Clone)]
47pub enum CardanoDbSnapshotCommands {
48 #[clap(arg_required_else_help = false)]
50 List(CardanoDbListCommand),
51
52 #[clap(arg_required_else_help = true)]
54 Show(CardanoDbShowCommand),
55}
56
57impl CardanoDbCommands {
58 pub async fn execute(&self, context: CommandContext) -> MithrilResult<()> {
60 match self {
61 Self::Download(cmd) => cmd.execute(context).await,
62 Self::Snapshot(cmd) => cmd.execute(context).await,
63 Self::Verify(cmd) => cmd.execute(context).await,
64 }
65 }
66}
67
68impl CardanoDbSnapshotCommands {
69 pub async fn execute(&self, config_builder: CommandContext) -> MithrilResult<()> {
71 match self {
72 Self::List(cmd) => cmd.execute(config_builder).await,
73 Self::Show(cmd) => cmd.execute(config_builder).await,
74 }
75 }
76}
77
78pub fn warn_deprecated_v1_backend(context: &CommandContext) {
80 use crate::utils::JSON_CAUTION_KEY;
81
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 if context.is_json_output_enabled() {
87 eprintln!(r#"{{"{JSON_CAUTION_KEY}":"{message}"}}"#);
88 } else {
89 eprintln!("Warning: {message}");
90 }
91}
92
93pub fn warn_unused_parameter_with_v1_backend<const N: usize>(
95 context: &CommandContext,
96 v2_only_parameters: [&str; N],
97) {
98 use crate::utils::JSON_CAUTION_KEY;
99
100 let message = format_unused_parameter_with_v1_backend(v2_only_parameters);
101 if context.is_json_output_enabled() {
102 eprintln!(r#"{{"{JSON_CAUTION_KEY}":"{message}"}}"#);
103 } else {
104 eprintln!("{message}");
105 eprintln!();
107 }
108}
109
110fn format_unused_parameter_with_v1_backend<const N: usize>(
111 v2_only_parameters: [&str; N],
112) -> String {
113 match v2_only_parameters.len() {
114 0 => String::new(),
115 1 => format!(
116 "`{}` is only available with the `v2` backend. It will be ignored.",
117 v2_only_parameters[0]
118 ),
119 n => {
120 format!(
121 "`{}`, and `{}` are only available with the `v2` backend. They will be ignored.",
122 v2_only_parameters[..n - 1].join("`, `"),
123 v2_only_parameters[n - 1]
124 )
125 }
126 }
127}
128
129#[cfg(test)]
130mod tests {
131 use super::*;
132
133 #[test]
134 fn test_format_unused_parameter_with_v1_backend() {
135 assert_eq!(format_unused_parameter_with_v1_backend([]), String::new());
136
137 assert_eq!(
138 format_unused_parameter_with_v1_backend(["--test"]),
139 "`--test` is only available with the `v2` backend. It will be ignored.".to_string()
140 );
141
142 assert_eq!(
143 format_unused_parameter_with_v1_backend(["--foo", "--bar"]),
144 "`--foo`, and `--bar` are only available with the `v2` backend. They will be ignored."
145 .to_string()
146 );
147
148 assert_eq!(
149 format_unused_parameter_with_v1_backend(["--test", "--foo", "--bar"]),
150 "`--test`, `--foo`, and `--bar` are only available with the `v2` backend. They will be ignored.".to_string()
151 );
152 }
153}