@@ -11,8 +11,8 @@ pub struct Command {
11
11
#[ structopt( long = "enable-process-subreaper" , short = "s" , env = "ENABLE_PROCESS_SUBREAPER" ) ]
12
12
enable_process_subreaper : bool ,
13
13
14
- #[ structopt( long = "with-istio" , env = "WITH_ISTIO" ) ]
15
- with_istio : bool ,
14
+ #[ structopt( long = "with-istio" , env = "WITH_ISTIO" , parse ( from_str = parse_bool_str ) ) ]
15
+ with_istio : Option < bool > ,
16
16
17
17
#[ structopt(
18
18
long = "pilot-agent-endpoint" ,
@@ -21,8 +21,8 @@ pub struct Command {
21
21
) ]
22
22
pilot_agent_endpoint : String ,
23
23
24
- #[ structopt( long = "kill-istio" , env = "KILL_ISTIO" ) ]
25
- kill_istio : bool ,
24
+ #[ structopt( long = "kill-istio" , env = "KILL_ISTIO" , parse ( from_str = parse_bool_str ) ) ]
25
+ kill_istio : Option < bool > ,
26
26
27
27
command : String ,
28
28
@@ -49,12 +49,28 @@ impl Into<Config> for Command {
49
49
50
50
let process = config:: Process { command, args } ;
51
51
52
- let istio = if with_istio {
53
- Some ( config:: Istio { pilot_agent_endpoint, kill_istio } )
52
+ let istio = if let Some ( true ) = with_istio {
53
+ Some ( config:: Istio { pilot_agent_endpoint, kill_istio : kill_istio . unwrap_or ( false ) } )
54
54
} else {
55
55
None
56
56
} ;
57
57
58
58
Config { enable_process_subreaper, process, istio }
59
59
}
60
60
}
61
+
62
+ fn parse_bool_str ( s : & str ) -> bool { !matches ! ( s, "" | "false" ) }
63
+
64
+ #[ cfg( test) ]
65
+ mod tests {
66
+
67
+ #[ test]
68
+ fn test_parse_bool_str ( ) {
69
+ use super :: parse_bool_str;
70
+
71
+ assert_eq ! ( parse_bool_str( "" ) , false ) ;
72
+ assert_eq ! ( parse_bool_str( "false" ) , false ) ;
73
+ assert_eq ! ( parse_bool_str( "true" ) , true ) ;
74
+ assert_eq ! ( parse_bool_str( "any" ) , true ) ;
75
+ }
76
+ }
0 commit comments