11use crate :: json:: JsonValueCommand ;
2+ use crate :: non_empty_separator;
23use crate :: ValueReader ;
34use clap:: Args ;
45use serde_json:: { Map , Value } ;
@@ -18,7 +19,7 @@ pub struct EnvArgs {
1819 #[ arg( long) ]
1920 expand_path : bool ,
2021 /// Separator to use when expanding the Path variable. Defaults to the platform-specific separator.
21- #[ arg( long, requires = "expand_path" ) ]
22+ #[ arg( long, requires = "expand_path" , value_parser = non_empty_separator ) ]
2223 path_separator : Option < String > ,
2324}
2425
@@ -103,6 +104,12 @@ mod tests {
103104 use crate :: testing:: TestBuffer ;
104105 use serde_json:: json;
105106
107+ #[ derive( clap:: Parser , Debug ) ]
108+ struct EnvArgsParser {
109+ #[ command( flatten) ]
110+ args : EnvArgs ,
111+ }
112+
106113 fn env_args_from_stdin ( ) -> EnvArgs {
107114 let mut args = EnvArgs :: default ( ) ;
108115 args. from_stdin = true ;
@@ -356,4 +363,11 @@ mod tests {
356363 args. expand_path_variable ( & mut json_value) ;
357364 assert_eq ! ( json_value[ "PATH" ] , json!( [ "/usr/bin" , "/bin" ] ) ) ;
358365 }
366+
367+ #[ test]
368+ fn empty_path_separator_is_rejected ( ) {
369+ use clap:: Parser ;
370+ let result = EnvArgsParser :: try_parse_from ( [ "cmd" , "--expand-path" , "--path-separator=" ] ) ;
371+ assert ! ( result. is_err( ) ) ;
372+ }
359373}
0 commit comments