@@ -3,9 +3,9 @@ use std::fmt::Debug;
3
3
use std:: mem;
4
4
use std:: path:: { Path , PathBuf } ;
5
5
6
+ use clap:: ValueEnum ;
6
7
use futures:: TryFutureExt ;
7
8
use log:: { info, warn} ;
8
- use martin_tile_utils:: TileInfo ;
9
9
use serde:: { Deserialize , Serialize } ;
10
10
use url:: Url ;
11
11
@@ -62,6 +62,31 @@ pub enum FileError {
62
62
CogError ( #[ from] crate :: cog:: CogError ) ,
63
63
}
64
64
65
+ #[ derive( PartialEq , Eq , Debug , Clone , Copy , Default , Serialize , Deserialize , ValueEnum ) ]
66
+ #[ serde( rename_all = "lowercase" ) ]
67
+ pub enum ValidationLevel {
68
+ /// Quickly check the source
69
+ #[ default]
70
+ Fast ,
71
+
72
+ /// Do a slow check of everything
73
+ Thorough ,
74
+ }
75
+
76
+ #[ derive( PartialEq , Eq , Debug , Clone , Copy , Default , Serialize , Deserialize , ValueEnum ) ]
77
+ #[ serde( rename_all = "lowercase" ) ]
78
+ pub enum OnInvalid {
79
+ /// Print warning message, and abort if the error is critical
80
+ #[ default]
81
+ Warn ,
82
+
83
+ /// Skip this source
84
+ Ignore ,
85
+
86
+ /// Do not start Martin on any warnings
87
+ Abort ,
88
+ }
89
+
65
90
pub trait ConfigExtras : Clone + Debug + Default + PartialEq + Send {
66
91
fn init_parsing ( & mut self , _cache : OptMainCache ) -> FileResult < ( ) > {
67
92
Ok ( ( ) )
@@ -130,6 +155,8 @@ impl<T: ConfigExtras> FileConfigEnum<T> {
130
155
} else {
131
156
Some ( configs)
132
157
} ,
158
+ validate : None ,
159
+ on_invalid : None ,
133
160
custom,
134
161
} )
135
162
}
@@ -187,6 +214,10 @@ pub struct FileConfig<T> {
187
214
pub paths : OptOneMany < PathBuf > ,
188
215
/// A map of source IDs to file paths or config objects
189
216
pub sources : Option < BTreeMap < String , FileConfigSrc > > ,
217
+ #[ serde( default ) ]
218
+ pub validate : Option < ValidationLevel > ,
219
+ #[ serde( default ) ]
220
+ pub on_invalid : Option < OnInvalid > ,
190
221
/// Any customizations related to the specifics of the configuration section
191
222
#[ serde( flatten) ]
192
223
pub custom : T ,
@@ -275,10 +306,7 @@ async fn resolve_int<T: SourceConfigExtras>(
275
306
let dup = if dup { "duplicate " } else { "" } ;
276
307
let id = idr. resolve ( & id, url. to_string ( ) ) ;
277
308
configs. insert ( id. clone ( ) , source) ;
278
- maybe_add_source (
279
- & mut results,
280
- cfg. custom . new_sources_url ( id. clone ( ) , url. clone ( ) ) . await ,
281
- ) ?;
309
+ results. push ( cfg. custom . new_sources_url ( id. clone ( ) , url. clone ( ) ) . await ?) ;
282
310
info ! ( "Configured {dup}source {id} from {}" , sanitize_url( & url) ) ;
283
311
} else {
284
312
let can = source. abs_path ( ) ?;
@@ -292,10 +320,7 @@ async fn resolve_int<T: SourceConfigExtras>(
292
320
let id = idr. resolve ( & id, can. to_string_lossy ( ) . to_string ( ) ) ;
293
321
info ! ( "Configured {dup}source {id} from {}" , can. display( ) ) ;
294
322
configs. insert ( id. clone ( ) , source. clone ( ) ) ;
295
- maybe_add_source (
296
- & mut results,
297
- cfg. custom . new_sources ( id, source. into_path ( ) ) . await ,
298
- ) ?;
323
+ results. push ( cfg. custom . new_sources ( id, source. into_path ( ) ) . await ?) ;
299
324
}
300
325
}
301
326
}
@@ -319,10 +344,7 @@ async fn resolve_int<T: SourceConfigExtras>(
319
344
320
345
let id = idr. resolve ( id, url. to_string ( ) ) ;
321
346
configs. insert ( id. clone ( ) , FileConfigSrc :: Path ( path) ) ;
322
- maybe_add_source (
323
- & mut results,
324
- cfg. custom . new_sources_url ( id. clone ( ) , url. clone ( ) ) . await ,
325
- ) ?;
347
+ results. push ( cfg. custom . new_sources_url ( id. clone ( ) , url. clone ( ) ) . await ?) ;
326
348
info ! ( "Configured source {id} from URL {}" , sanitize_url( & url) ) ;
327
349
} else {
328
350
let is_dir = path. is_dir ( ) ;
@@ -351,7 +373,7 @@ async fn resolve_int<T: SourceConfigExtras>(
351
373
info ! ( "Configured source {id} from {}" , can. display( ) ) ;
352
374
files. insert ( can) ;
353
375
configs. insert ( id. clone ( ) , FileConfigSrc :: Path ( path. clone ( ) ) ) ;
354
- maybe_add_source ( & mut results, cfg. custom . new_sources ( id, path) . await ) ? ;
376
+ results. push ( cfg. custom . new_sources ( id, path) . await ? ) ;
355
377
}
356
378
}
357
379
}
0 commit comments