@@ -6,8 +6,10 @@ use std::{collections::HashMap, ffi::OsString, io};
6
6
7
7
use camino:: { Utf8Path , Utf8PathBuf } ;
8
8
use convert_case:: { Case , Casing } ;
9
+ use derive_setters:: Setters ;
9
10
use env:: { EnvVars , OverrideEnvVars } ;
10
11
use file:: { AuthFile , ConfigFile } ;
12
+ use merge:: Merge ;
11
13
use miette:: { Diagnostic , NamedSource , SourceSpan } ;
12
14
use serde:: Deserialize ;
13
15
use struct_iterable:: Iterable ;
@@ -173,15 +175,6 @@ pub enum Error {
173
175
} ,
174
176
}
175
177
176
- macro_rules! create_builder {
177
- ( $func_name: ident, $property_name: ident, $type: ty) => {
178
- pub fn $func_name( mut self , value: $type) -> Self {
179
- self . override_config. $property_name = value;
180
- self
181
- }
182
- } ;
183
- }
184
-
185
178
const DEFAULT_API_URL : & str = "https://vercel.com/api" ;
186
179
const DEFAULT_LOGIN_URL : & str = "https://vercel.com" ;
187
180
const DEFAULT_TIMEOUT : u64 = 30 ;
@@ -190,8 +183,13 @@ const DEFAULT_UPLOAD_TIMEOUT: u64 = 60;
190
183
// We intentionally don't derive Serialize so that different parts
191
184
// of the code that want to display the config can tune how they
192
185
// want to display and what fields they want to include.
193
- #[ derive( Deserialize , Default , Debug , PartialEq , Eq , Clone , Iterable ) ]
186
+ #[ derive( Deserialize , Default , Debug , PartialEq , Eq , Clone , Iterable , Merge , Setters ) ]
194
187
#[ serde( rename_all = "camelCase" ) ]
188
+ // Generate setters for the builder type that set these values on its override_config field
189
+ #[ setters(
190
+ prefix = "with_" ,
191
+ generate_delegates( ty = "TurborepoConfigBuilder" , field = "override_config" )
192
+ ) ]
195
193
pub struct ConfigurationOptions {
196
194
#[ serde( alias = "apiurl" ) ]
197
195
#[ serde( alias = "ApiUrl" ) ]
@@ -336,44 +334,6 @@ impl ConfigurationOptions {
336
334
}
337
335
}
338
336
339
- macro_rules! create_set_if_empty {
340
- ( $func_name: ident, $property_name: ident, $type: ty) => {
341
- fn $func_name( & mut self , value: & mut Option <$type>) {
342
- if self . $property_name. is_none( ) {
343
- if let Some ( value) = value. take( ) {
344
- self . $property_name = Some ( value) ;
345
- }
346
- }
347
- }
348
- } ;
349
- }
350
-
351
- // Private setters used only for construction
352
- impl ConfigurationOptions {
353
- create_set_if_empty ! ( set_api_url, api_url, String ) ;
354
- create_set_if_empty ! ( set_login_url, login_url, String ) ;
355
- create_set_if_empty ! ( set_team_slug, team_slug, String ) ;
356
- create_set_if_empty ! ( set_team_id, team_id, String ) ;
357
- create_set_if_empty ! ( set_token, token, String ) ;
358
- create_set_if_empty ! ( set_signature, signature, bool ) ;
359
- create_set_if_empty ! ( set_enabled, enabled, bool ) ;
360
- create_set_if_empty ! ( set_preflight, preflight, bool ) ;
361
- create_set_if_empty ! ( set_timeout, timeout, u64 ) ;
362
- create_set_if_empty ! ( set_ui, ui, UIMode ) ;
363
- create_set_if_empty ! ( set_allow_no_package_manager, allow_no_package_manager, bool ) ;
364
- create_set_if_empty ! ( set_daemon, daemon, bool ) ;
365
- create_set_if_empty ! ( set_env_mode, env_mode, EnvMode ) ;
366
- create_set_if_empty ! ( set_cache_dir, cache_dir, Utf8PathBuf ) ;
367
- create_set_if_empty ! ( set_scm_base, scm_base, String ) ;
368
- create_set_if_empty ! ( set_scm_head, scm_head, String ) ;
369
- create_set_if_empty ! ( set_spaces_id, spaces_id, String ) ;
370
- create_set_if_empty ! (
371
- set_root_turbo_json_path,
372
- root_turbo_json_path,
373
- AbsoluteSystemPathBuf
374
- ) ;
375
- }
376
-
377
337
// Maps Some("") to None to emulate how Go handles empty strings
378
338
fn non_empty_str ( s : Option < & str > ) -> Option < & str > {
379
339
s. filter ( |s| !s. is_empty ( ) )
@@ -428,30 +388,6 @@ impl TurborepoConfigBuilder {
428
388
. unwrap_or_else ( get_lowercased_env_vars)
429
389
}
430
390
431
- create_builder ! ( with_api_url, api_url, Option <String >) ;
432
- create_builder ! ( with_login_url, login_url, Option <String >) ;
433
- create_builder ! ( with_team_slug, team_slug, Option <String >) ;
434
- create_builder ! ( with_team_id, team_id, Option <String >) ;
435
- create_builder ! ( with_token, token, Option <String >) ;
436
- create_builder ! ( with_signature, signature, Option <bool >) ;
437
- create_builder ! ( with_enabled, enabled, Option <bool >) ;
438
- create_builder ! ( with_preflight, preflight, Option <bool >) ;
439
- create_builder ! ( with_timeout, timeout, Option <u64 >) ;
440
- create_builder ! ( with_ui, ui, Option <UIMode >) ;
441
- create_builder ! (
442
- with_allow_no_package_manager,
443
- allow_no_package_manager,
444
- Option <bool >
445
- ) ;
446
- create_builder ! ( with_daemon, daemon, Option <bool >) ;
447
- create_builder ! ( with_env_mode, env_mode, Option <EnvMode >) ;
448
- create_builder ! ( with_cache_dir, cache_dir, Option <Utf8PathBuf >) ;
449
- create_builder ! (
450
- with_root_turbo_json_path,
451
- root_turbo_json_path,
452
- Option <AbsoluteSystemPathBuf >
453
- ) ;
454
-
455
391
pub fn build ( & self ) -> Result < ConfigurationOptions , Error > {
456
392
// Priority, from least significant to most significant:
457
393
// - shared configuration (turbo.json)
@@ -483,27 +419,8 @@ impl TurborepoConfigBuilder {
483
419
let config = sources. into_iter ( ) . try_fold (
484
420
ConfigurationOptions :: default ( ) ,
485
421
|mut acc, current_source| {
486
- let mut current_source_config = current_source. get_configuration_options ( & acc) ?;
487
- acc. set_api_url ( & mut current_source_config. api_url ) ;
488
- acc. set_login_url ( & mut current_source_config. login_url ) ;
489
- acc. set_team_slug ( & mut current_source_config. team_slug ) ;
490
- acc. set_team_id ( & mut current_source_config. team_id ) ;
491
- acc. set_token ( & mut current_source_config. token ) ;
492
- acc. set_signature ( & mut current_source_config. signature ) ;
493
- acc. set_enabled ( & mut current_source_config. enabled ) ;
494
- acc. set_preflight ( & mut current_source_config. preflight ) ;
495
- acc. set_timeout ( & mut current_source_config. timeout ) ;
496
- acc. set_spaces_id ( & mut current_source_config. spaces_id ) ;
497
- acc. set_ui ( & mut current_source_config. ui ) ;
498
- acc. set_allow_no_package_manager (
499
- & mut current_source_config. allow_no_package_manager ,
500
- ) ;
501
- acc. set_daemon ( & mut current_source_config. daemon ) ;
502
- acc. set_env_mode ( & mut current_source_config. env_mode ) ;
503
- acc. set_scm_base ( & mut current_source_config. scm_base ) ;
504
- acc. set_scm_head ( & mut current_source_config. scm_head ) ;
505
- acc. set_cache_dir ( & mut current_source_config. cache_dir ) ;
506
- acc. set_root_turbo_json_path ( & mut current_source_config. root_turbo_json_path ) ;
422
+ let current_source_config = current_source. get_configuration_options ( & acc) ?;
423
+ acc. merge ( current_source_config) ;
507
424
Ok ( acc)
508
425
} ,
509
426
) ;
0 commit comments