@@ -61,8 +61,12 @@ pub fn run_shadow<'a>(args: Vec<&'a OsStr>) -> anyhow::Result<()> {
61
61
}
62
62
. into ( ) ;
63
63
64
+ // this option is weird since it's a configuration option but we need to read it before merging
65
+ // with the configuration file
66
+ let use_extended_yaml = options. experimental . use_extended_yaml . unwrap_or_default ( ) ;
67
+
64
68
// load the configuration yaml
65
- let config_file = load_config_file ( & config_filename)
69
+ let config_file = load_config_file ( & config_filename, use_extended_yaml )
66
70
. with_context ( || format ! ( "Failed to load configuration file {}" , config_filename) ) ?;
67
71
68
72
// generate the final shadow configuration from the config file and cli options
@@ -179,7 +183,10 @@ pub fn run_shadow<'a>(args: Vec<&'a OsStr>) -> anyhow::Result<()> {
179
183
Ok ( ( ) )
180
184
}
181
185
182
- fn load_config_file ( filename : impl AsRef < std:: path:: Path > ) -> anyhow:: Result < ConfigFileOptions > {
186
+ fn load_config_file (
187
+ filename : impl AsRef < std:: path:: Path > ,
188
+ extended_yaml : bool ,
189
+ ) -> anyhow:: Result < ConfigFileOptions > {
183
190
let file = std:: fs:: File :: open ( filename) . context ( "Could not open config file" ) ?;
184
191
185
192
// serde's default behaviour is to silently ignore duplicate keys during deserialization so we
@@ -191,23 +198,25 @@ fn load_config_file(filename: impl AsRef<std::path::Path>) -> anyhow::Result<Con
191
198
let mut config_file: serde_yaml:: Value =
192
199
serde_yaml:: from_reader ( file) . context ( "Could not parse configuration file as yaml" ) ?;
193
200
194
- // apply the merge before removing extension fields
195
- config_file
196
- . apply_merge ( )
197
- . context ( "Could not merge '<<' keys" ) ?;
198
-
199
- // remove top-level extension fields
200
- if let serde_yaml:: Value :: Mapping ( ref mut mapping) = & mut config_file {
201
- // remove entries having a key beginning with "x-" (follows docker's convention:
202
- // https://docs.docker.com/compose/compose-file/#extension)
203
- mapping. retain ( |key, _value| {
204
- if let serde_yaml:: Value :: String ( key) = key {
205
- if key. starts_with ( "x-" ) {
206
- return false ;
201
+ if extended_yaml {
202
+ // apply the merge before removing extension fields
203
+ config_file
204
+ . apply_merge ( )
205
+ . context ( "Could not merge '<<' keys" ) ?;
206
+
207
+ // remove top-level extension fields
208
+ if let serde_yaml:: Value :: Mapping ( ref mut mapping) = & mut config_file {
209
+ // remove entries having a key beginning with "x-" (follows docker's convention:
210
+ // https://docs.docker.com/compose/compose-file/#extension)
211
+ mapping. retain ( |key, _value| {
212
+ if let serde_yaml:: Value :: String ( key) = key {
213
+ if key. starts_with ( "x-" ) {
214
+ return false ;
215
+ }
207
216
}
208
- }
209
- true
210
- } ) ;
217
+ true
218
+ } ) ;
219
+ }
211
220
}
212
221
213
222
Ok ( serde_yaml:: from_value ( config_file) . context ( "Could not parse configuration file" ) ?)
0 commit comments