11use std:: time:: Duration ;
22
33use clap:: ValueEnum ;
4+ use enum_display:: EnumDisplay ;
45use log:: { info, warn} ;
56use serde:: { Deserialize , Serialize } ;
67
@@ -13,8 +14,11 @@ use crate::utils::{OptBoolObj, OptOneMany};
1314// Must match the help string for BoundsType::Quick
1415pub const DEFAULT_BOUNDS_TIMEOUT : Duration = Duration :: from_secs ( 5 ) ;
1516
16- #[ derive( PartialEq , Eq , Default , Debug , Clone , Copy , Serialize , Deserialize , ValueEnum ) ]
17+ #[ derive(
18+ PartialEq , Eq , Default , Debug , Clone , Copy , Serialize , Deserialize , ValueEnum , EnumDisplay ,
19+ ) ]
1720#[ serde( rename_all = "lowercase" ) ]
21+ #[ enum_display( case = "Kebab" ) ]
1822pub enum BoundsCalcType {
1923 /// Compute table geometry bounds, but abort if it takes longer than 5 seconds.
2024 #[ default]
@@ -37,7 +41,7 @@ pub struct PgArgs {
3741 /// If a spatial PG table has SRID 0, then this default SRID will be used as a fallback.
3842 #[ arg( short, long) ]
3943 pub default_srid : Option < i32 > ,
40- #[ arg( help = format!( "Maximum Postgres connections pool size [DEFAULT: {}]" , POOL_SIZE_DEFAULT ) , short, long) ]
44+ #[ arg( help = format!( "Maximum Postgres connections pool size [DEFAULT: {POOL_SIZE_DEFAULT }]" ) , short, long) ]
4145 pub pool_size : Option < usize > ,
4246 /// Limit the number of features in a tile from a PG table source.
4347 #[ arg( short, long) ]
@@ -76,31 +80,46 @@ impl PgArgs {
7680 }
7781 }
7882
83+ /// Apply CLI parameters from `self` to the configuration loaded from the config file `pg_config`
7984 pub fn override_config < ' a > ( self , pg_config : & mut OptOneMany < PgConfig > , env : & impl Env < ' a > ) {
80- if self . default_srid . is_some ( ) {
81- info ! ( "Overriding configured default SRID to {} on all Postgres connections because of a CLI parameter" , self . default_srid. unwrap( ) ) ;
85+ // This ensures that if a new parameter is added to the struct, it will not be forgotten here
86+ let Self {
87+ default_srid,
88+ pool_size,
89+ auto_bounds,
90+ max_feature_count,
91+ ca_root_file,
92+ } = self ;
93+
94+ if let Some ( value) = default_srid {
95+ info ! ( "Overriding configured default SRID to {value} on all Postgres connections because of a CLI parameter" ) ;
8296 pg_config. iter_mut ( ) . for_each ( |c| {
83- c. default_srid = self . default_srid ;
97+ c. default_srid = default_srid;
8498 } ) ;
8599 }
86- if self . pool_size . is_some ( ) {
87- info ! ( "Overriding configured pool size to {} on all Postgres connections because of a CLI parameter" , self . pool_size . unwrap ( ) ) ;
100+ if let Some ( value ) = pool_size {
101+ info ! ( "Overriding configured pool size to {value } on all Postgres connections because of a CLI parameter" ) ;
88102 pg_config. iter_mut ( ) . for_each ( |c| {
89- c. pool_size = self . pool_size ;
103+ c. pool_size = pool_size;
90104 } ) ;
91105 }
92- if self . max_feature_count . is_some ( ) {
93- info ! ( "Overriding maximum feature count to {} on all Postgres connections because of a CLI parameter" , self . max_feature_count . unwrap ( ) ) ;
106+ if let Some ( value ) = auto_bounds {
107+ info ! ( "Overriding auto_bounds to {value } on all Postgres connections because of a CLI parameter" ) ;
94108 pg_config. iter_mut ( ) . for_each ( |c| {
95- c. max_feature_count = self . max_feature_count ;
109+ c. auto_bounds = auto_bounds ;
96110 } ) ;
97111 }
98-
99- if self . ca_root_file . is_some ( ) {
112+ if let Some ( value) = max_feature_count {
113+ info ! ( "Overriding maximum feature count to {value} on all Postgres connections because of a CLI parameter" ) ;
114+ pg_config. iter_mut ( ) . for_each ( |c| {
115+ c. max_feature_count = max_feature_count;
116+ } ) ;
117+ }
118+ if let Some ( ref value) = ca_root_file {
100119 info ! ( "Overriding root certificate file to {} on all Postgres connections because of a CLI parameter" ,
101- self . ca_root_file . as_ref ( ) . unwrap ( ) . display( ) ) ;
120+ value . display( ) ) ;
102121 pg_config. iter_mut ( ) . for_each ( |c| {
103- c. ssl_certificates . ssl_root_cert = self . ca_root_file . clone ( ) ;
122+ c. ssl_certificates . ssl_root_cert = ca_root_file. clone ( ) ;
104123 } ) ;
105124 }
106125
0 commit comments