@@ -2,14 +2,15 @@ use std::fs;
22
33use toml_edit:: { Array , DocumentMut , InlineTable , Item , Table , Value } ;
44
5- use crate :: { CFG_TARGET_OS_WINDOWS , CONFIG_COMMUNITY , CONFIG_MALEFIC_WIN_KIT_PATH , CONFIG_PROFESSIONAL , DEFAULT , DEPENDENCES , DEPENDENCICES , FEATURES , MALEFIC_WIN_KIT , PATH , TARGET } ;
5+ use crate :: { Service , CFG_TARGET_OS_WINDOWS , COMMON_TRANSPORT_TCP , COMMON_TRANSPORT_TLS , CONFIG_COMMUNITY , CONFIG_MALEFIC_WIN_KIT_PATH , CONFIG_PROFESSIONAL , DEFAULT , DEPENDENCES , DEPENDENCICES , FEATURES , MALEFIC_WIN_KIT , PATH , TARGET } ;
66
7- pub fn update_helper_toml ( cargo_toml_path : & str , professional : bool ) {
7+ pub fn update_helper_toml ( cargo_toml_path : & str , service : Service , professional : bool ) {
88 let cargo_toml_content = fs:: read_to_string ( cargo_toml_path)
99 . expect ( "Failed to read Cargo.toml file" ) ;
1010
1111 let mut cargo_toml: DocumentMut = cargo_toml_content. parse ( )
1212 . expect ( "Failed to parse Cargo.toml file" ) ;
13+ // Set the default feature to community or professional
1314 if let Some ( features) = cargo_toml[ & FEATURES ] . as_table_mut ( ) {
1415 if let Some ( default_array) = features[ & DEFAULT ] . as_array_mut ( ) {
1516 if !professional {
@@ -26,6 +27,24 @@ pub fn update_helper_toml(cargo_toml_path: &str, professional: bool) {
2627 }
2728 }
2829 }
30+
31+ // Set the default feature common
32+ if let Some ( features) = cargo_toml[ & FEATURES ] . as_table_mut ( ) {
33+ if let Some ( default_array) = features[ & DEFAULT ] . as_array_mut ( ) {
34+ if service. tls {
35+ if default_array. iter ( ) . find ( |x| x. as_str ( ) . unwrap ( ) == & COMMON_TRANSPORT_TLS . to_string ( ) ) . is_none ( ) {
36+ default_array. push ( COMMON_TRANSPORT_TLS . to_string ( ) ) ;
37+ }
38+ default_array. retain ( |x| x. as_str ( ) . unwrap ( ) != & COMMON_TRANSPORT_TCP . to_string ( ) ) ;
39+ } else {
40+ if default_array. iter ( ) . find ( |x| x. as_str ( ) . unwrap ( ) == & COMMON_TRANSPORT_TCP . to_string ( ) ) . is_none ( ) {
41+ default_array. push ( COMMON_TRANSPORT_TCP . to_string ( ) ) ;
42+ }
43+ default_array. retain ( |x| x. as_str ( ) . unwrap ( ) != & COMMON_TRANSPORT_TLS . to_string ( ) ) ;
44+ }
45+ }
46+ }
47+
2948 if let Some ( target) = cargo_toml[ & TARGET ] . as_table_mut ( ) {
3049 if let Some ( target_os) = target[ & CFG_TARGET_OS_WINDOWS ] . as_table_mut ( ) {
3150 if let Some ( dependencies) = target_os[ & DEPENDENCICES ] . as_table_mut ( ) {
0 commit comments