@@ -74,3 +74,65 @@ impl CardanoDbSnapshotCommands {
7474 }
7575 }
7676}
77+
78+ /// Print in stderr that the given parameters are not available with the v1 backend and will be ignored
79+ pub fn warn_unused_parameter_with_v1_backend < const N : usize > (
80+ context : & CommandContext ,
81+ v2_only_parameters : [ & str ; N ] ,
82+ ) {
83+ use crate :: utils:: JSON_CAUTION_KEY ;
84+
85+ let message = format_unused_parameter_with_v1_backend ( v2_only_parameters) ;
86+ if context. is_json_output_enabled ( ) {
87+ eprintln ! ( r#"{{"{JSON_CAUTION_KEY}":"{message}"}}"# ) ;
88+ } else {
89+ eprintln ! ( "{message}" ) ;
90+ // Add a blank line to separate this message from the one related to the fast bootstrap that comes next.
91+ eprintln ! ( ) ;
92+ }
93+ }
94+
95+ fn format_unused_parameter_with_v1_backend < const N : usize > (
96+ v2_only_parameters : [ & str ; N ] ,
97+ ) -> String {
98+ match v2_only_parameters. len ( ) {
99+ 0 => String :: new ( ) ,
100+ 1 => format ! (
101+ "`{}` is only available with the `v2` backend. It will be ignored." ,
102+ v2_only_parameters[ 0 ]
103+ ) ,
104+ n => {
105+ format ! (
106+ "`{}`, and `{}` are only available with the `v2` backend. They will be ignored." ,
107+ v2_only_parameters[ ..n - 1 ] . join( "`, `" ) ,
108+ v2_only_parameters[ n - 1 ]
109+ )
110+ }
111+ }
112+ }
113+
114+ #[ cfg( test) ]
115+ mod tests {
116+ use super :: * ;
117+
118+ #[ test]
119+ fn test_format_unused_parameter_with_v1_backend ( ) {
120+ assert_eq ! ( format_unused_parameter_with_v1_backend( [ ] ) , String :: new( ) ) ;
121+
122+ assert_eq ! (
123+ format_unused_parameter_with_v1_backend( [ "--test" ] ) ,
124+ "`--test` is only available with the `v2` backend. It will be ignored." . to_string( )
125+ ) ;
126+
127+ assert_eq ! (
128+ format_unused_parameter_with_v1_backend( [ "--foo" , "--bar" ] ) ,
129+ "`--foo`, and `--bar` are only available with the `v2` backend. They will be ignored."
130+ . to_string( )
131+ ) ;
132+
133+ assert_eq ! (
134+ format_unused_parameter_with_v1_backend( [ "--test" , "--foo" , "--bar" ] ) ,
135+ "`--test`, `--foo`, and `--bar` are only available with the `v2` backend. They will be ignored." . to_string( )
136+ ) ;
137+ }
138+ }
0 commit comments